Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove duplicate method symlink(item) #758

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

the-eversio
Copy link
Contributor

Description:

Looks like there was some duplicate code here. I've kept the two methods but updated the public method to call the internal one.

Comment on lines -149 to -196
if not item:
logger.error("Invalid item sent to Symlinker: None")
return False

if item.file is None:
logger.error(f"Item file is None for {item.log_string}, cannot create symlink.")
return False

if not item.folder:
logger.error(f"Item folder is None for {item.log_string}, cannot create symlink.")
return False

filename = self._determine_file_name(item)
if not filename:
logger.error(f"Symlink filename is None for {item.log_string}, cannot create symlink.")
return False

extension = os.path.splitext(item.file)[1][1:]
symlink_filename = f"{filename}.{extension}"
destination = self._create_item_folders(item, symlink_filename)
source = os.path.join(self.rclone_path, item.folder, item.file)

try:
if os.path.islink(destination):
os.remove(destination)
os.symlink(source, destination)
except PermissionError as e:
# This still creates the symlinks, however they will have wrong perms. User needs to fix their permissions.
# TODO: Maybe we validate symlink class by symlinking a test file, then try removing it and see if it still exists
logger.exception(f"Permission denied when creating symlink for {item.log_string}: {e}")
except OSError as e:
if e.errno == 36:
# This will cause a loop if it hits this.. users will need to fix their paths
# TODO: Maybe create an alternative naming scheme to cover this?
logger.error(f"Filename too long when creating symlink for {item.log_string}: {e}")
else:
logger.error(f"OS error when creating symlink for {item.log_string}: {e}")
return False

if os.readlink(destination) != source:
logger.error(f"Symlink validation failed: {destination} does not point to {source} for {item.log_string}")
return False

item.set("symlinked", True)
item.set("symlinked_at", datetime.now())
item.set("symlinked_times", item.symlinked_times + 1)
item.set("symlink_path", destination)
return True
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section looks line-for-line identical with _symlink, I think it was just a copy-paste error.

@Gaisberg Gaisberg merged commit 314bd5b into rivenmedia:main Oct 3, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants