# suchlike).
PDTCRYPT_EXTENSION = "pdtcrypt"
+AUXILIARY_FILE_INDEX = 0
+AUXILIARY_FILE_INFO = 1
+
class DeltaTar(object):
'''
Backup class used to create backups
return path[len(prefix):]
return path
- def open_index(self, path, mode='r', kind="index"):
+ def open_auxiliary_file(self, path, mode='r', kind=AUXILIARY_FILE_INDEX):
'''
- Given the specified configuration, opens the index for reading or
- writing. It transparently handles if the index is encrypted and/or
- compressed, returning a file object ready to use.
+ Given the specified configuration, opens a file for reading or writing,
+ inheriting the encryption and compression settings from the backup.
+ Returns a file object ready to use.
- :param kind: Role of file. The only special value is “info”
- which sets the appropriate counter in the crypto
- layer.
+ :param kind: Role of the file, see AUXILIARY_FILE_* constants. The
+ only special value is AUXILIARY_FILE_INFO which
+ sets the appropriate counter in the crypto layer.
:type kind: str
'''
if self.index_mode.startswith('gz'):
encver = None
counter = None
- if self.crypto_ctx is not None and kind == "info":
+ if self.crypto_ctx is not None and kind == AUXILIARY_FILE_INFO:
counter = crypto.AES_GCM_IV_CNT_INFOFILE
return tarfile._Stream(name=path, mode=mode, comptype=comptype,
# init index
index_name = self.index_name_func(True)
index_path = os.path.join(backup_path, index_name)
- index_fd = self.open_index(index_path, 'w') # **NOT** an fd
+ index_fd = self.open_auxiliary_file(index_path, 'w') # **NOT** an fd
if index_fd.encryption is not None:
self.nacl = index_fd.encryption.nacl
# init index
index_name = self.index_name_func(is_full=False)
index_path = os.path.join(backup_path, index_name)
- index_fd = self.open_index(index_path, 'w') # **NOT** an fd
+ index_fd = self.open_auxiliary_file(index_path, 'w') # **NOT** an fd
if index_fd.encryption is not None:
self.nacl = index_fd.encryption.nacl
Allows this iterator to be used with the "with" statement
'''
if self.f is None:
- self.f = self.delta_tar.open_index(self.index_path, 'r')
+ self.f = self.delta_tar.open_auxiliary_file(self.index_path, 'r')
# check index header
j, l_no = self.delta_tar._parse_json_line(self.f, 0)
if j.get("type", '') != 'python-delta-tar-index' or\