OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """The Volume Shadow Snapshots (VSS) file entry implementation.""" | 2 """The Volume Shadow Snapshots (VSS) file entry implementation.""" |
3 | 3 |
| 4 from __future__ import unicode_literals |
| 5 |
4 from dfdatetime import filetime as dfdatetime_filetime | 6 from dfdatetime import filetime as dfdatetime_filetime |
5 | 7 |
6 from dfvfs.lib import definitions | 8 from dfvfs.lib import definitions |
7 from dfvfs.lib import errors | 9 from dfvfs.lib import errors |
8 from dfvfs.lib import vshadow | 10 from dfvfs.lib import vshadow |
9 from dfvfs.path import vshadow_path_spec | 11 from dfvfs.path import vshadow_path_spec |
10 from dfvfs.vfs import file_entry | 12 from dfvfs.vfs import file_entry |
11 | 13 |
12 | 14 |
13 class VShadowDirectory(file_entry.Directory): | 15 class VShadowDirectory(file_entry.Directory): |
14 """File system directory that uses pyvshadow.""" | 16 """File system directory that uses pyvshadow.""" |
15 | 17 |
16 def _EntriesGenerator(self): | 18 def _EntriesGenerator(self): |
17 """Retrieves directory entries. | 19 """Retrieves directory entries. |
18 | 20 |
19 Since a directory can contain a vast number of entries using | 21 Since a directory can contain a vast number of entries using |
20 a generator is more memory efficient. | 22 a generator is more memory efficient. |
21 | 23 |
22 Yields: | 24 Yields: |
23 VShadowPathSpec: a path specification. | 25 VShadowPathSpec: a path specification. |
24 """ | 26 """ |
25 # Only the virtual root file has directory entries. | 27 # Only the virtual root file has directory entries. |
26 store_index = getattr(self.path_spec, u'store_index', None) | 28 store_index = getattr(self.path_spec, 'store_index', None) |
27 if store_index is not None: | 29 if store_index is not None: |
28 return | 30 return |
29 | 31 |
30 location = getattr(self.path_spec, u'location', None) | 32 location = getattr(self.path_spec, 'location', None) |
31 if location is None or location != self._file_system.LOCATION_ROOT: | 33 if location is None or location != self._file_system.LOCATION_ROOT: |
32 return | 34 return |
33 | 35 |
34 vshadow_volume = self._file_system.GetVShadowVolume() | 36 vshadow_volume = self._file_system.GetVShadowVolume() |
35 | 37 |
36 for store_index in range(0, vshadow_volume.number_of_stores): | 38 for store_index in range(0, vshadow_volume.number_of_stores): |
37 yield vshadow_path_spec.VShadowPathSpec( | 39 yield vshadow_path_spec.VShadowPathSpec( |
38 location=u'/vss{0:d}'.format(store_index + 1), | 40 location='/vss{0:d}'.format(store_index + 1), |
39 store_index=store_index, parent=self.path_spec.parent) | 41 store_index=store_index, parent=self.path_spec.parent) |
40 | 42 |
41 | 43 |
42 class VShadowFileEntry(file_entry.FileEntry): | 44 class VShadowFileEntry(file_entry.FileEntry): |
43 """File system file entry that uses pyvshadow.""" | 45 """File system file entry that uses pyvshadow.""" |
44 | 46 |
45 TYPE_INDICATOR = definitions.TYPE_INDICATOR_VSHADOW | 47 TYPE_INDICATOR = definitions.TYPE_INDICATOR_VSHADOW |
46 | 48 |
47 def __init__( | 49 def __init__( |
48 self, resolver_context, file_system, path_spec, is_root=False, | 50 self, resolver_context, file_system, path_spec, is_root=False, |
49 is_virtual=False): | 51 is_virtual=False): |
50 """Initializes a file entry. | 52 """Initializes a file entry. |
51 | 53 |
52 Args: | 54 Args: |
53 resolver_context (Context): resolver context. | 55 resolver_context (Context): resolver context. |
54 file_system (FileSystem): file system. | 56 file_system (FileSystem): file system. |
55 path_spec (PathSpec): path specification. | 57 path_spec (PathSpec): path specification. |
56 is_root (Optional[bool]): True if the file entry is the root file entry | 58 is_root (Optional[bool]): True if the file entry is the root file entry |
57 of the corresponding file system. | 59 of the corresponding file system. |
58 is_virtual (Optional[bool]): True if the file entry is a virtual file | 60 is_virtual (Optional[bool]): True if the file entry is a virtual file |
59 entry emulated by the corresponding file system. | 61 entry emulated by the corresponding file system. |
60 | 62 |
61 Raises: | 63 Raises: |
62 BackEndError: when the vshadow store is missing in a non-virtual | 64 BackEndError: when the vshadow store is missing in a non-virtual |
63 file entry. | 65 file entry. |
64 """ | 66 """ |
65 vshadow_store = file_system.GetVShadowStoreByPathSpec(path_spec) | 67 vshadow_store = file_system.GetVShadowStoreByPathSpec(path_spec) |
66 if not is_virtual and vshadow_store is None: | 68 if not is_virtual and vshadow_store is None: |
67 raise errors.BackEndError( | 69 raise errors.BackEndError( |
68 u'Missing vshadow store in non-virtual file entry.') | 70 'Missing vshadow store in non-virtual file entry.') |
69 | 71 |
70 super(VShadowFileEntry, self).__init__( | 72 super(VShadowFileEntry, self).__init__( |
71 resolver_context, file_system, path_spec, is_root=is_root, | 73 resolver_context, file_system, path_spec, is_root=is_root, |
72 is_virtual=is_virtual) | 74 is_virtual=is_virtual) |
73 self._name = None | 75 self._name = None |
74 self._vshadow_store = vshadow_store | 76 self._vshadow_store = vshadow_store |
75 | 77 |
76 if self._is_virtual: | 78 if self._is_virtual: |
77 self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY | 79 self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY |
78 else: | 80 else: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 def creation_time(self): | 117 def creation_time(self): |
116 """dfdatetime.DateTimeValues: creation time or None if not available.""" | 118 """dfdatetime.DateTimeValues: creation time or None if not available.""" |
117 if self._vshadow_store is not None: | 119 if self._vshadow_store is not None: |
118 timestamp = self._vshadow_store.get_creation_time_as_integer() | 120 timestamp = self._vshadow_store.get_creation_time_as_integer() |
119 return dfdatetime_filetime.Filetime(timestamp=timestamp) | 121 return dfdatetime_filetime.Filetime(timestamp=timestamp) |
120 | 122 |
121 @property | 123 @property |
122 def name(self): | 124 def name(self): |
123 """str: name of the file entry, which does not include the full path.""" | 125 """str: name of the file entry, which does not include the full path.""" |
124 if self._name is None: | 126 if self._name is None: |
125 location = getattr(self.path_spec, u'location', None) | 127 location = getattr(self.path_spec, 'location', None) |
126 if location is not None: | 128 if location is not None: |
127 self._name = self._file_system.BasenamePath(location) | 129 self._name = self._file_system.BasenamePath(location) |
128 else: | 130 else: |
129 store_index = getattr(self.path_spec, u'store_index', None) | 131 store_index = getattr(self.path_spec, 'store_index', None) |
130 if store_index is not None: | 132 if store_index is not None: |
131 self._name = u'vss{0:d}'.format(store_index + 1) | 133 self._name = 'vss{0:d}'.format(store_index + 1) |
132 else: | 134 else: |
133 self._name = u'' | 135 self._name = '' |
134 return self._name | 136 return self._name |
135 | 137 |
136 @property | 138 @property |
137 def sub_file_entries(self): | 139 def sub_file_entries(self): |
138 """generator[FileEntry]: sub file entries.""" | 140 """generator[FileEntry]: sub file entries.""" |
139 if self._directory is None: | 141 if self._directory is None: |
140 self._directory = self._GetDirectory() | 142 self._directory = self._GetDirectory() |
141 | 143 |
142 if self._directory: | 144 if self._directory: |
143 for path_spec in self._directory.entries: | 145 for path_spec in self._directory.entries: |
(...skipping 23 matching lines...) Expand all Loading... |
167 def HasExternalData(self): | 169 def HasExternalData(self): |
168 """Determines if the file entry has external stored data. | 170 """Determines if the file entry has external stored data. |
169 | 171 |
170 Returns: | 172 Returns: |
171 bool: True if the file entry has external data. | 173 bool: True if the file entry has external data. |
172 """ | 174 """ |
173 if self._vshadow_store is None: | 175 if self._vshadow_store is None: |
174 return False | 176 return False |
175 | 177 |
176 return not self._vshadow_store.has_in_volume_data() | 178 return not self._vshadow_store.has_in_volume_data() |
OLD | NEW |