-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 task
the-eversio
commented
Oct 2, 2024
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 |
There was a problem hiding this comment.
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
approved these changes
Oct 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.