def test_create_checksum_file(self):
     test_file = tempfile.NamedTemporaryFile(dir=self.tmp_dir_1, delete=True)
     test_file.write(b"test\n")
     test_file.flush()
     FileUtil.create_checksum_file(test_file.name, '715a9aa9257aadb001e1b85c858b0a91')
     self.assertTrue(os.path.exists(test_file.name + '.done'))
     with open(test_file.name + '.done') as f:
         line = f.readline()
         self.assertEqual(line.strip(), '715a9aa9257aadb001e1b85c858b0a91' + ' ' + os.path.basename(test_file.name))
 def test_create_checksum_file(self):
     test_file = tempfile.NamedTemporaryFile(dir=self.tmp_dir_1,
                                             delete=True)
     test_file.write(b"test\n")
     test_file.flush()
     FileUtil.create_checksum_file(test_file.name,
                                   '715a9aa9257aadb001e1b85c858b0a91')
     self.assertTrue(os.path.exists(test_file.name + '.done'))
     with open(test_file.name + '.done') as f:
         line = f.readline()
         self.assertEqual(
             line.strip(), '715a9aa9257aadb001e1b85c858b0a91' + ' ' +
             os.path.basename(test_file.name))
Example #3
0
    def handle_missing_checksum_files(self):
        """Handle checksum files generation logic

        The method will generate checksum files for the source files which miss checksum file pair in the file_stats
        If a checksum file which is missing in the snapshot is actually available on the filesystem the entire file pair
        will dropped for next iteration
        """
        all_files = self.file_stats.keys()
        # filter out the checksum files which will contain the checksum for a corresponding source file
        source_files = set(all_files) - set(fnmatch.filter(all_files, '*' + Const.CHECKSUM_FILE_EXTENSION))
        for file in source_files:
            checksum_file = FileUtil.get_complement_file_name(file)
            if checksum_file not in all_files:
                if not os.path.exists(checksum_file):
                    # create checksum file if does not exist (uses md5 checksum)
                    system_checksum_file = FileUtil.create_checksum_file(source_file=file,
                                                                         file_hash=self.hasher.get_file_hash(file))
                    self.add_file_to_snapshot(system_checksum_file)
                else:
                    # looks like the checksum file exists on filesystem (could have been dropped late)
                    # the file pair will be dropped for next iteration
                    self.remove_file_pair_from_dict(file)
Example #4
0
 def _create_checksum(self, source_file):
     ''' creates a md5 checksum file for `source_file`. '''
     checksum_value = self.hasher.get_file_hash(source_file)
     return FileUtil.create_checksum_file(source_file, checksum_value)
 def _create_checksum(self, source_file):
     ''' creates a md5 checksum file for `source_file`. '''
     checksum_value = self.hasher.get_file_hash(source_file)
     return FileUtil.create_checksum_file(source_file, checksum_value)