Skip to content

Commit

Permalink
Removed need to close file system object log2timeline#306 (log2timeli…
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Jan 11, 2021
1 parent 810fd42 commit 23b05cc
Show file tree
Hide file tree
Showing 51 changed files with 7 additions and 261 deletions.
5 changes: 1 addition & 4 deletions dfvfs/helpers/source_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,8 @@ def ScanForFileSystem(self, source_path_spec):
# Check if the file system can be opened since the file system by
# signature detection results in false positives.
try:
file_system = resolver.Resolver.OpenFileSystem(
resolver.Resolver.OpenFileSystem(
file_system_path_spec, resolver_context=self._resolver_context)
file_system.Close()
except errors.BackEndError:
file_system_path_spec = None

Expand Down Expand Up @@ -767,8 +766,6 @@ def ScanForStorageMediaImage(self, source_path_spec):
except errors.PathSpecError:
glob_results = None

file_system.Close()

if not glob_results:
return None

Expand Down
8 changes: 1 addition & 7 deletions dfvfs/helpers/volume_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,19 +665,13 @@ def _ScanFileSystem(self, scan_node, base_path_specs):
raise errors.ScannerError('Invalid or missing file system scan node.')

file_system = resolver.Resolver.OpenFileSystem(scan_node.path_spec)
if not file_system:
return

try:
if file_system:
path_resolver = windows_path_resolver.WindowsPathResolver(
file_system, scan_node.path_spec.parent)

if self._ScanFileSystemForWindowsDirectory(path_resolver):
base_path_specs.append(scan_node.path_spec)

finally:
file_system.Close()

def _ScanFileSystemForWindowsDirectory(self, path_resolver):
"""Scans a file system for a known Windows directory.
Expand Down
10 changes: 4 additions & 6 deletions dfvfs/vfs/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import abc

from dfvfs.lib import decorators


class FileSystem(object):
"""Virtual file system interface."""
Expand Down Expand Up @@ -81,19 +83,15 @@ def BasenamePath(self, path):
_, _, basename = path.rpartition(self.PATH_SEPARATOR)
return basename

@decorators.deprecated
def Close(self):
"""Closes the file system.
Raises:
IOError: if the file system object was not opened or the close failed.
OSError: if the file system object was not opened or the close failed.
"""
if not self._is_open:
raise IOError('Not opened.')

self._Close()
self._is_open = False
self._path_spec = None
return

def DirnamePath(self, path):
"""Determines the directory name of the path.
Expand Down
2 changes: 0 additions & 2 deletions tests/vfs/apfs_container_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down Expand Up @@ -77,7 +76,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down
8 changes: 0 additions & 8 deletions tests/vfs/apfs_container_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def testOpenAndClose(self):

file_system.Open()

file_system.Close()

def testFileEntryExistsByPathSpec(self):
"""Test the file entry exists by path specification functionality."""
file_system = apfs_container_file_system.APFSContainerFileSystem(
Expand Down Expand Up @@ -74,8 +72,6 @@ def testFileEntryExistsByPathSpec(self):
location='/apfs9', parent=self._raw_path_spec)
self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

file_system.Close()

def testGetFileEntryByPathSpec(self):
"""Tests the GetFileEntryByPathSpec function."""
file_system = apfs_container_file_system.APFSContainerFileSystem(
Expand Down Expand Up @@ -123,8 +119,6 @@ def testGetFileEntryByPathSpec(self):

self.assertIsNone(file_entry)

file_system.Close()

def testGetRootFileEntry(self):
"""Test the get root file entry functionality."""
file_system = apfs_container_file_system.APFSContainerFileSystem(
Expand All @@ -138,8 +132,6 @@ def testGetRootFileEntry(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()

# TODO: add tests for GetAPFSVolumeByPathSpec function.


Expand Down
3 changes: 0 additions & 3 deletions tests/vfs/apfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down Expand Up @@ -89,7 +88,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down Expand Up @@ -430,7 +428,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down
8 changes: 0 additions & 8 deletions tests/vfs/apfs_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def testOpenAndClose(self):

file_system.Open()

file_system.Close()

def testFileEntryExistsByPathSpec(self):
"""Test the file entry exists by path specification functionality."""
file_system = apfs_file_system.APFSFileSystem(
Expand All @@ -67,8 +65,6 @@ def testFileEntryExistsByPathSpec(self):
parent=self._apfs_container_path_spec)
self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

file_system.Close()

def testGetFileEntryByPathSpec(self):
"""Tests the GetFileEntryByPathSpec function."""
file_system = apfs_file_system.APFSFileSystem(
Expand Down Expand Up @@ -104,8 +100,6 @@ def testGetFileEntryByPathSpec(self):

self.assertIsNone(file_entry)

file_system.Close()

# TODO: add tests for GetAPFSFileEntryByPathSpec function.

def testGetRootFileEntry(self):
Expand All @@ -121,8 +115,6 @@ def testGetRootFileEntry(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()


if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion tests/vfs/bde_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testIntialize(self):
Expand Down
8 changes: 0 additions & 8 deletions tests/vfs/bde_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def testOpenAndClose(self):

file_system.Open()

file_system.Close()

def testFileEntryExistsByPathSpec(self):
"""Test the file entry exists by path specification functionality."""
file_system = bde_file_system.BDEFileSystem(
Expand All @@ -56,8 +54,6 @@ def testFileEntryExistsByPathSpec(self):
result = file_system.FileEntryExistsByPathSpec(self._bde_path_spec)
self.assertTrue(result)

file_system.Close()

def testGetFileEntryByPathSpec(self):
"""Tests the GetFileEntryByPathSpec function."""
file_system = bde_file_system.BDEFileSystem(
Expand All @@ -70,8 +66,6 @@ def testGetFileEntryByPathSpec(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()

def testGetRootFileEntry(self):
"""Test the get root file entry functionality."""
file_system = bde_file_system.BDEFileSystem(
Expand All @@ -84,8 +78,6 @@ def testGetRootFileEntry(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()


if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion tests/vfs/compressed_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down
8 changes: 0 additions & 8 deletions tests/vfs/compressed_stream_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def testOpenAndClose(self):

file_system.Open()

file_system.Close()

def testFileEntryExistsByPathSpec(self):
"""Test the file entry exists by path specification functionality."""
file_system = compressed_stream_file_system.CompressedStreamFileSystem(
Expand All @@ -53,8 +51,6 @@ def testFileEntryExistsByPathSpec(self):
self.assertTrue(file_system.FileEntryExistsByPathSpec(
self._compressed_stream_path_spec))

file_system.Close()

def testGetFileEntryByPathSpec(self):
"""Tests the GetFileEntryByPathSpec function."""
file_system = compressed_stream_file_system.CompressedStreamFileSystem(
Expand All @@ -69,8 +65,6 @@ def testGetFileEntryByPathSpec(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()

def testGetRootFileEntry(self):
"""Test the get root file entry functionality."""
file_system = compressed_stream_file_system.CompressedStreamFileSystem(
Expand All @@ -84,8 +78,6 @@ def testGetRootFileEntry(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()


if __name__ == '__main__':
unittest.main()
2 changes: 0 additions & 2 deletions tests/vfs/cpio_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down Expand Up @@ -72,7 +71,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testIntialize(self):
Expand Down
8 changes: 0 additions & 8 deletions tests/vfs/cpio_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def testOpenAndClose(self):

file_system.Open()

file_system.Close()

def testFileEntryExistsByPathSpec(self):
"""Test the file entry exists by path specification functionality."""
file_system = cpio_file_system.CPIOFileSystem(
Expand All @@ -59,8 +57,6 @@ def testFileEntryExistsByPathSpec(self):
parent=self._os_path_spec)
self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

file_system.Close()

def testGetFileEntryByPathSpec(self):
"""Tests the GetFileEntryByPathSpec function."""
file_system = cpio_file_system.CPIOFileSystem(
Expand All @@ -84,8 +80,6 @@ def testGetFileEntryByPathSpec(self):

self.assertIsNone(file_entry)

file_system.Close()

def testGetRootFileEntry(self):
"""Test the get root file entry functionality."""
file_system = cpio_file_system.CPIOFileSystem(
Expand All @@ -99,8 +93,6 @@ def testGetRootFileEntry(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()

# TODO: add tests for GetCPIOArchiveFileEntryByPathSpec function.


Expand Down
1 change: 0 additions & 1 deletion tests/vfs/data_range_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down
8 changes: 0 additions & 8 deletions tests/vfs/data_range_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def testOpenAndClose(self):

file_system.Open()

file_system.Close()

def testFileEntryExistsByPathSpec(self):
"""Test the file entry exists by path specification functionality."""
file_system = data_range_file_system.DataRangeFileSystem(
Expand All @@ -51,8 +49,6 @@ def testFileEntryExistsByPathSpec(self):
self.assertTrue(file_system.FileEntryExistsByPathSpec(
self._data_range_path_spec))

file_system.Close()

def testGetFileEntryByPathSpec(self):
"""Tests the GetFileEntryByPathSpec function."""
file_system = data_range_file_system.DataRangeFileSystem(
Expand All @@ -67,8 +63,6 @@ def testGetFileEntryByPathSpec(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()

def testGetRootFileEntry(self):
"""Test the get root file entry functionality."""
file_system = data_range_file_system.DataRangeFileSystem(
Expand All @@ -82,8 +76,6 @@ def testGetRootFileEntry(self):
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

file_system.Close()


if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion tests/vfs/encoded_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def setUp(self):

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._file_system.Close()
self._resolver_context.Empty()

def testInitialize(self):
Expand Down
Loading

0 comments on commit 23b05cc

Please sign in to comment.