def __init__(self, ref_dirsnap, dirsnap): """ """ self._files_deleted = list() self._files_modified = list() self._files_created = list() self._files_moved = list() self._dirs_modified = list() self._dirs_moved = list() self._dirs_deleted = list() self._dirs_created = list() paths_moved_from_not_deleted = [] paths_deleted = set() paths_created = set() # Detect all the modifications. for path, stat_info in dirsnap.stat_snapshot.items(): if path in ref_dirsnap.stat_snapshot: ref_stat_info = ref_dirsnap.stat_info(path) if stat_info.st_ino == ref_stat_info.st_ino and stat_info.st_mtime != ref_stat_info.st_mtime: if stat.S_ISDIR(stat_info.st_mode): self._dirs_modified.append(path) else: self._files_modified.append(path) elif stat_info.st_ino != ref_stat_info.st_ino: # Same path exists... but different inode if ref_dirsnap.has_inode(stat_info.st_ino): old_path = ref_dirsnap.path_for_inode(stat_info.st_ino) paths_deleted.add( path ) # remember that the previous same-named file was deleted paths_moved_from_not_deleted.append(old_path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_moved.append((old_path, path)) else: self._files_moved.append((old_path, path)) else: # we have a newly created item with existing name, but different inode paths_deleted.add(path) paths_created.add(path) paths_deleted = paths_deleted | ((ref_dirsnap.paths - dirsnap.paths) - set(paths_moved_from_not_deleted)) paths_created = paths_created | (dirsnap.paths - ref_dirsnap.paths) # Detect all the moves/renames. # Doesn't work on Windows, so exclude on Windows. if not sys.platform.startswith('win'): for created_path in paths_created.copy(): created_stat_info = dirsnap.stat_info(created_path) for deleted_path in paths_deleted.copy(): deleted_stat_info = ref_dirsnap.stat_info(deleted_path) if created_stat_info.st_ino == deleted_stat_info.st_ino: paths_deleted.remove(deleted_path) paths_created.remove(created_path) if stat.S_ISDIR(created_stat_info.st_mode): self._dirs_moved.append( (deleted_path, created_path)) else: self._files_moved.append( (deleted_path, created_path)) # Now that we have renames out of the way, enlist the deleted and # created files/directories. for path in paths_deleted: stat_info = ref_dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_deleted.append(path) else: self._files_deleted.append(path) for path in paths_created: stat_info = dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_created.append(path) else: self._files_created.append(path)
def __init__(self, ref_dirsnap, dirsnap): """ """ self._files_deleted = list() self._files_modified = list() self._files_created = list() self._files_moved = list() self._dirs_modified = list() self._dirs_moved = list() self._dirs_deleted = list() self._dirs_created = list() paths_moved_from_not_deleted = [] paths_deleted = set() paths_created = set() # Detect modifications and distinguish modifications that are actually # renames of files on top of existing file names (OS X/Linux only) for path, stat_info in list(dirsnap.stat_snapshot.items()): if path in ref_dirsnap.stat_snapshot: ref_stat_info = ref_dirsnap.stat_info(path) if stat_info.st_ino == ref_stat_info.st_ino and stat_info.st_mtime != ref_stat_info.st_mtime: if stat.S_ISDIR(stat_info.st_mode): self._dirs_modified.append(path) else: self._files_modified.append(path) elif stat_info.st_ino != ref_stat_info.st_ino: # Same path exists... but different inode if ref_dirsnap.has_inode(stat_info.st_ino): old_path = ref_dirsnap.path_for_inode(stat_info.st_ino) paths_moved_from_not_deleted.append(old_path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_moved.append((old_path, path)) else: self._files_moved.append((old_path, path)) else: # we have a newly created item with existing name, but different inode paths_deleted.add(path) paths_created.add(path) paths_deleted = paths_deleted | ((ref_dirsnap.paths - dirsnap.paths) - set(paths_moved_from_not_deleted)) paths_created = paths_created | (dirsnap.paths - ref_dirsnap.paths) # Detect all the moves/renames except for atomic renames on top of existing files # that are handled in the file modification check for-loop above # Doesn't work on Windows since st_ino is always 0, so exclude on Windows. if not sys.platform.startswith('win'): for created_path in paths_created: created_stat_info = dirsnap.stat_info(created_path) for deleted_path in paths_deleted: deleted_stat_info = ref_dirsnap.stat_info(deleted_path) if created_stat_info.st_ino == deleted_stat_info.st_ino: paths_deleted.remove(deleted_path) paths_created.remove(created_path) if stat.S_ISDIR(created_stat_info.st_mode): self._dirs_moved.append( (deleted_path, created_path)) else: self._files_moved.append( (deleted_path, created_path)) # Now that we have renames out of the way, enlist the deleted and # created files/directories. for path in paths_deleted: stat_info = ref_dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_deleted.append(path) else: self._files_deleted.append(path) for path in paths_created: stat_info = dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_created.append(path) else: self._files_created.append(path)
def paths(self): """ List of file/directory paths in the snapshot. """ return set(self._stat_snapshot)
def __init__(self, ref_dirsnap, dirsnap): """ """ self._files_deleted = list() self._files_modified = list() self._files_created = list() self._files_moved = list() self._dirs_modified = list() self._dirs_moved = list() self._dirs_deleted = list() self._dirs_created = list() paths_moved_from_not_deleted = [] paths_deleted = set() paths_created = set() # Detect modifications and distinguish modifications that are actually # renames of files on top of existing file names (OS X/Linux only) for path, stat_info in list(dirsnap.stat_snapshot.items()): if path in ref_dirsnap.stat_snapshot: ref_stat_info = ref_dirsnap.stat_info(path) if stat_info.st_ino == ref_stat_info.st_ino and stat_info.st_mtime != ref_stat_info.st_mtime: if stat.S_ISDIR(stat_info.st_mode): self._dirs_modified.append(path) else: self._files_modified.append(path) elif stat_info.st_ino != ref_stat_info.st_ino: # Same path exists... but different inode if ref_dirsnap.has_inode(stat_info.st_ino): old_path = ref_dirsnap.path_for_inode(stat_info.st_ino) paths_moved_from_not_deleted.append(old_path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_moved.append((old_path, path)) else: self._files_moved.append((old_path, path)) else: # we have a newly created item with existing name, but different inode paths_deleted.add(path) paths_created.add(path) paths_deleted = paths_deleted | ((ref_dirsnap.paths - dirsnap.paths) - set(paths_moved_from_not_deleted)) paths_created = paths_created | (dirsnap.paths - ref_dirsnap.paths) # Detect all the moves/renames except for atomic renames on top of existing files # that are handled in the file modification check for-loop above # Doesn't work on Windows since st_ino is always 0, so exclude on Windows. if not sys.platform.startswith('win'): for created_path in paths_created: created_stat_info = dirsnap.stat_info(created_path) for deleted_path in paths_deleted: deleted_stat_info = ref_dirsnap.stat_info(deleted_path) if created_stat_info.st_ino == deleted_stat_info.st_ino: paths_deleted.remove(deleted_path) paths_created.remove(created_path) if stat.S_ISDIR(created_stat_info.st_mode): self._dirs_moved.append((deleted_path, created_path)) else: self._files_moved.append((deleted_path, created_path)) # Now that we have renames out of the way, enlist the deleted and # created files/directories. for path in paths_deleted: stat_info = ref_dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_deleted.append(path) else: self._files_deleted.append(path) for path in paths_created: stat_info = dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_created.append(path) else: self._files_created.append(path)
def __init__(self, ref_dirsnap, dirsnap): """ """ self.pool_manager = Pool(processes=3) self._files_deleted = list() self._files_modified = list() self._files_created = list() self._files_moved = list() self._files_accessed = list() self._dirs_modified = list() self._dirs_moved = list() self._dirs_deleted = list() self._dirs_created = list() paths_moved_from_not_deleted = [] paths_deleted = set() paths_created = set() self.inspector = None try: self.inspector = collector.File_Inspector(False, False, collector.database_handler) except Exception as e: print 'Error in File_Inspector() in dirsnapshot.' print e print 'Dirsnapshot 0.5 __init__()' # Detect modifications and distinguish modifications that are actually # renames of files on top of existing file names (OS X/Linux only) for path, stat_info in list(dirsnap.stat_snapshot.items()): if path in ref_dirsnap.stat_snapshot: ref_stat_info = ref_dirsnap.stat_info(path) if stat_info.st_ino == ref_stat_info.st_ino and stat_info.st_mtime != ref_stat_info.st_mtime: if stat.S_ISDIR(stat_info.st_mode): self._dirs_modified.append(path) else: print 'File Modified: %s' % path try: self.pool_manager.apply_async( self.inspector.update_file_metadata_counters, (path, False)) except Exception as e: print e print 'Error in dirsnapshot modified' self._files_modified.append(path) if stat_info.st_ino == ref_stat_info.st_ino and stat_info.st_atime != ref_stat_info.st_atime: if not stat.S_ISDIR(stat_info.st_mode): try: print 'File Accessed %s | atime: %s ref_atime: %s' % (path, stat_info.st_atime, ref_stat_info.st_atime) self.pool_manager.apply_async( self.inspector.update_file_metadata_counters, (path, True)) except Exception as e: print e print 'Error in dirsnapshot accessed' self._files_accessed.append(path) elif stat_info.st_ino != ref_stat_info.st_ino: # Same path exists... but different inode if ref_dirsnap.has_inode(stat_info.st_ino): old_path = ref_dirsnap.path_for_inode(stat_info.st_ino) paths_moved_from_not_deleted.append(old_path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_moved.append((old_path, path)) else: print 'File Moved: %s' % path #self.inspector.update_file_metadata(path) self.pool_manager.apply_async( self.inspector.delete_file_metadata , (old_path) ) self.pool_manager.apply_async( self.inspector.add_file_metadata, (path)) self._files_moved.append((old_path, path)) else: # we have a newly created item with existing name, but different inode paths_deleted.add(path) paths_created.add(path) paths_deleted = paths_deleted | ( (ref_dirsnap.paths - dirsnap.paths) - set(paths_moved_from_not_deleted)) paths_created = paths_created | (dirsnap.paths - ref_dirsnap.paths) # Detect all the moves/renames except for atomic renames on top of existing files # that are handled in the file modification check for-loop above # Doesn't work on Windows since st_ino is always 0, so exclude on Windows. if not sys.platform.startswith('win'): for created_path in paths_created: created_stat_info = dirsnap.stat_info(created_path) for deleted_path in paths_deleted: deleted_stat_info = ref_dirsnap.stat_info(deleted_path) if created_stat_info.st_ino == deleted_stat_info.st_ino: paths_deleted.remove(deleted_path) paths_created.remove(created_path) if stat.S_ISDIR(created_stat_info.st_mode): self._dirs_moved.append((deleted_path, created_path)) else: print 'File Moved: %s' % created_path self.pool_manager.apply_async( self.inspector.delete_file_metadata, (deleted_path) ) self.pool_manager.apply_async( self.inspector.add_file_metadata, (created_path) ) self._files_moved.append((deleted_path, created_path)) # Now that we have renames out of the way, enlist the deleted and # created files/directories. for path in paths_deleted: stat_info = ref_dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_deleted.append(path) else: print 'File Deleted: %s' % path self.pool_manager.apply_async( self.inspector.delete_file_metadata, (path) ) self._files_deleted.append(path) for path in paths_created: stat_info = dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_created.append(path) else: print 'File Created: %s' % path self.pool_manager.apply_async( self.inspector.add_file_metadata, (path) ) self._files_created.append(path)
def __init__(self, ref_dirsnap, dirsnap): """ """ self._files_deleted = list() self._files_modified = list() self._files_created = list() self._files_moved = list() self._dirs_modified = list() self._dirs_moved = list() self._dirs_deleted = list() self._dirs_created = list() paths_moved_from_not_deleted = [] paths_deleted = set() paths_created = set() for path, stat_info in list(dirsnap.stat_snapshot.items()): if path in ref_dirsnap.stat_snapshot: ref_stat_info = ref_dirsnap.stat_info(path) if stat_info.st_ino == ref_stat_info.st_ino and stat_info.st_mtime != ref_stat_info.st_mtime: if stat.S_ISDIR(stat_info.st_mode): self._dirs_modified.append(path) else: self._files_modified.append(path) elif stat_info.st_ino != ref_stat_info.st_ino: if ref_dirsnap.has_inode(stat_info.st_ino): old_path = ref_dirsnap.path_for_inode(stat_info.st_ino) paths_moved_from_not_deleted.append(old_path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_moved.append((old_path, path)) else: self._files_moved.append((old_path, path)) else: paths_deleted.add(path) paths_created.add(path) paths_deleted = paths_deleted | ref_dirsnap.paths - dirsnap.paths - set(paths_moved_from_not_deleted) paths_created = paths_created | dirsnap.paths - ref_dirsnap.paths if not sys.platform.startswith('win'): for created_path in paths_created: created_stat_info = dirsnap.stat_info(created_path) for deleted_path in paths_deleted: deleted_stat_info = ref_dirsnap.stat_info(deleted_path) if created_stat_info.st_ino == deleted_stat_info.st_ino: paths_deleted.remove(deleted_path) paths_created.remove(created_path) if stat.S_ISDIR(created_stat_info.st_mode): self._dirs_moved.append((deleted_path, created_path)) else: self._files_moved.append((deleted_path, created_path)) for path in paths_deleted: stat_info = ref_dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_deleted.append(path) else: self._files_deleted.append(path) for path in paths_created: stat_info = dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_created.append(path) else: self._files_created.append(path)
def __init__(self, ref_dirsnap, dirsnap): """ """ self._files_deleted = list() self._files_modified = list() self._files_created = list() self._files_moved = list() self._dirs_modified = list() self._dirs_moved = list() self._dirs_deleted = list() self._dirs_created = list() paths_moved_from_not_deleted = [] paths_deleted = set() paths_created = set() # Detect all the modifications. for path, stat_info in dirsnap.stat_snapshot.items(): if path in ref_dirsnap.stat_snapshot: ref_stat_info = ref_dirsnap.stat_info(path) if stat_info.st_ino == ref_stat_info.st_ino and stat_info.st_mtime != ref_stat_info.st_mtime: if stat.S_ISDIR(stat_info.st_mode): self._dirs_modified.append(path) else: self._files_modified.append(path) elif stat_info.st_ino != ref_stat_info.st_ino: # Same path exists... but different inode if ref_dirsnap.has_inode(stat_info.st_ino): old_path = ref_dirsnap.path_for_inode(stat_info.st_ino) paths_deleted.add(path) # remember that the previous same-named file was deleted paths_moved_from_not_deleted.append(old_path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_moved.append((old_path, path)) else: self._files_moved.append((old_path, path)) else: # we have a newly created item with existing name, but different inode paths_deleted.add(path) paths_created.add(path) paths_deleted = paths_deleted | ((ref_dirsnap.paths - dirsnap.paths) - set(paths_moved_from_not_deleted)) paths_created = paths_created | (dirsnap.paths - ref_dirsnap.paths) # Detect all the moves/renames. # Doesn't work on Windows, so exclude on Windows. if not sys.platform.startswith('win'): for created_path in paths_created.copy(): created_stat_info = dirsnap.stat_info(created_path) for deleted_path in paths_deleted.copy(): deleted_stat_info = ref_dirsnap.stat_info(deleted_path) if created_stat_info.st_ino == deleted_stat_info.st_ino: paths_deleted.remove(deleted_path) paths_created.remove(created_path) if stat.S_ISDIR(created_stat_info.st_mode): self._dirs_moved.append((deleted_path, created_path)) else: self._files_moved.append((deleted_path, created_path)) # Now that we have renames out of the way, enlist the deleted and # created files/directories. for path in paths_deleted: stat_info = ref_dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_deleted.append(path) else: self._files_deleted.append(path) for path in paths_created: stat_info = dirsnap.stat_info(path) if stat.S_ISDIR(stat_info.st_mode): self._dirs_created.append(path) else: self._files_created.append(path)