Skip to content

Commit

Permalink
trying to change ownership of files for network shares
Browse files Browse the repository at this point in the history
  • Loading branch information
msmhome committed Aug 1, 2024
1 parent 1c5f9da commit 38e34a7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class FaxEventHandler(FileSystemEventHandler):
def __init__(self):
super().__init__()
self.fax_id_to_file = {}
# Root is needed to own the files in docker so that if upload via network share, the container can process the file from multiple users.
self.user_id = 0
self.group_id = 0

def on_created(self, event):
print(f"Event detected: {event}")
Expand All @@ -160,11 +163,28 @@ def on_created(self, event):
if event.event_type == 'created' and event.src_path.endswith('.pdf'):
self.process_fax(event.src_path)

def on_moved(self, event):
print(f"Event detected: {event}")
if event.is_directory:
return
if event.event_type == 'moved' and event.dest_path.endswith('.pdf'):
self.process_fax(event.dest_path)

def process_fax(self, file_path):
print(f"Processing fax for file: {file_path}")
file_name = os.path.basename(file_path)
fax_number = os.path.splitext(file_name)[0] # Extract fax number from file name
self.send_fax(file_path, fax_number)
# Change ownership of the file to root
try:
os.chown(file_path, self.user_id, self.group_id)
print(f"Changed ownership of {file_path} to user {self.user_id} and group {self.group_id}")
except OSError as e:
print(f"Failed to change ownership of {file_path}: {e}")

def set_user_group_ids(self, user_id, group_id):
self.user_id = user_id
self.group_id = group_id

def send_fax(self, file_path, fax_number, on_success_callback=None):
print(f"Sending fax to {fax_number} for file: {file_path}")
Expand Down

0 comments on commit 38e34a7

Please sign in to comment.