Skip to content

Commit

Permalink
INTEGRITY: Add Megadata class
Browse files Browse the repository at this point in the history
  • Loading branch information
InariInDream committed Jun 13, 2024
1 parent 55526be commit 6a37e43
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions megadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
import time
import compute_hash

class Megadata:
def __init__(self, file_path):
self.file_path = file_path
self.hash = self.calculate_hash(file_path)
self.size = os.path.getsize(file_path)
self.creation_time = os.path.getctime(file_path)
self.modification_time = os.path.getmtime(file_path)

def calculate_hash(self, file_path):
pass

def __eq__(self, other):
return (self.hash == other.hash and
self.size == other.size and
self.creation_time == other.creation_time and
self.modification_time == other.modification_time)


def record_megadata(directory):
file_megadata = {}
for root, _, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
file_megadata[file_path] = Megadata(file_path)
return file_megadata

def check_for_updates(old_megadata, current_directory):
current_megadata = record_megadata(current_directory)
updates = []
for old_path, old_data in old_megadata.items():
for current_path, current_data in current_megadata.items():
if old_data == current_data and old_path != current_path:
updates.append((old_path, current_path))
return updates

0 comments on commit 6a37e43

Please sign in to comment.