Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_file_ident_equals():
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
fi.new(False, False, b'foo', None)
fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
fi2.new(False, False, b'foo', None)
assert(fi == fi2)
def test_file_ident_lt_one_parent():
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
fi.new(False, True, b'foo', None)
fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
fi2.new(False, False, b'hoo', None)
assert(fi < fi2)
def test_file_ident_new_initialized_twice():
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
fi.new(False, False, b'foo', None)
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
fi.new(False, False, b'foo', None)
assert(str(excinfo.value) == 'UDF File Identifier already initialized')
def test_file_ident_is_parent_not_initialized():
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
fi.is_parent()
assert(str(excinfo.value) == 'UDF File Identifier Descriptor not initialized')
def test_file_ident_parse_initialized_twice():
tag = pycdlib.udf.UDFTag()
tag.new(0, 0)
entry = pycdlib.udf.UDFFileEntry()
entry.new(0, 'dir', None, 2048)
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
fi.parse(b'\x00'*16 + b'\x01\x00\x08\x00' + b'\x00'*16 + b'\x00\x00', 0, tag, entry)
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
fi.parse(b'\x00'*16 + b'\x01\x00\x08\x00' + b'\x00'*16 + b'\x00\x00', 0, tag, entry)
assert(str(excinfo.value) == 'UDF File Identifier Descriptor already initialized')
def test_file_ident_parse_bad_encoding():
tag = pycdlib.udf.UDFTag()
tag.new(0, 0)
entry = pycdlib.udf.UDFFileEntry()
entry.new(0, 'dir', None, 2048)
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
fi.parse(b'\x00'*16 + b'\x01\x00\x00\x01' + b'\x00'*16 + b'\x00\x00\x00', 0, tag, entry)
assert(str(excinfo.value) == 'Only UDF File Identifier Descriptor Encodings 8 or 16 are supported')
def test_file_ident_is_dir_not_initialized():
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
fi.is_dir()
assert(str(excinfo.value) == 'UDF File Identifier Descriptor not initialized')
def test_file_entry_add_file_ident_desc_bad_file_type():
entry = pycdlib.udf.UDFFileEntry()
entry.new(0, 'file', None, 2048)
desc = pycdlib.udf.UDFFileIdentifierDescriptor()
desc.new(False, False, b'foo', None)
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo:
entry.add_file_ident_desc(desc, 2048)
assert(str(excinfo.value) == 'Can only add a UDF File Identifier to a directory')
def test_file_ident_record_not_initialized():
fi = pycdlib.udf.UDFFileIdentifierDescriptor()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
fi.record()
assert(str(excinfo.value) == 'UDF File Identifier Descriptor not initialized')
Parameters:
new_fi_desc - The new UDF File Identifier Descriptor to add.
logical_block_size - The logical block size to use.
Returns:
The number of extents added due to adding this File Identifier Descriptor.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('UDF File Entry not initialized')
if self.icb_tag.file_type != 4:
raise pycdlibexception.PyCdlibInvalidInput('Can only add a UDF File Identifier to a directory')
self.fi_descs.append(new_fi_desc)
num_bytes_to_add = UDFFileIdentifierDescriptor.length(len(new_fi_desc.fi))
old_num_extents = 0
# If info_len is 0, then this is a brand-new File Entry, and thus the
# number of extents it is using is 0.
if self.info_len > 0:
old_num_extents = utils.ceiling_div(self.info_len, logical_block_size)
self.info_len += num_bytes_to_add
new_num_extents = utils.ceiling_div(self.info_len, logical_block_size)
self.log_block_recorded = new_num_extents
self.alloc_descs[0][0] = self.info_len
if new_fi_desc.is_dir():
self.file_link_count += 1