Skip to content

Commit

Permalink
feat: follow / ignore symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
F33RNI committed Jan 25, 2024
1 parent 31ca845 commit 584ee34
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
1 change: 1 addition & 0 deletions Backupper.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ def _generate_tree(
directories_to_parse_queue,
parsed_queue,
skipped_entries_abs,
self._config_manager.get_config("follow_symlinks"),
self._stats_tree_parsed_dirs,
self._stats_tree_parsed_files,
control_value,
Expand Down
1 change: 1 addition & 0 deletions ConfigManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"version": __version__,
"input_paths": [],
"save_to": "",
"follow_symlinks": False,
"delete_data": True,
"delete_skipped": False,
"create_empty_dirs": True,
Expand Down
4 changes: 4 additions & 0 deletions GUIHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(
self.cb_delete_data.setChecked(self._config_manager.get_config("delete_data"))
self.cb_delete_skipped.setChecked(self._config_manager.get_config("delete_skipped"))
self.cb_delete_skipped.setEnabled(self._config_manager.get_config("delete_data"))
self.cb_follow_symlinks.setChecked(self._config_manager.get_config("follow_symlinks"))
self.cb_create_empty_dirs.setChecked(self._config_manager.get_config("create_empty_dirs"))
self.cb_generate_tree.setChecked(self._config_manager.get_config("generate_tree"))
self.cob_checksum_alg.setCurrentText(self._config_manager.get_config("checksum_alg"))
Expand All @@ -162,6 +163,9 @@ def __init__(

# Connect updaters
self.le_save_to.textChanged.connect(lambda: self._config_manager.set_config("save_to", self.le_save_to.text()))
self.cb_follow_symlinks.clicked.connect(
lambda: self._config_manager.set_config("follow_symlinks", self.cb_follow_symlinks.isChecked())
)
self.cb_delete_data.clicked.connect(
lambda: self._config_manager.set_config("delete_data", self.cb_delete_data.isChecked())
)
Expand Down
46 changes: 38 additions & 8 deletions gui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>502</width>
<height>608</height>
<width>474</width>
<height>757</height>
</rect>
</property>
<property name="font">
Expand All @@ -28,17 +28,20 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>9</number>
</property>
<property name="leftMargin">
<number>12</number>
<number>9</number>
</property>
<property name="topMargin">
<number>12</number>
<number>9</number>
</property>
<property name="rightMargin">
<number>12</number>
<number>9</number>
</property>
<property name="bottomMargin">
<number>6</number>
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_3">
Expand Down Expand Up @@ -74,8 +77,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>474</width>
<height>137</height>
<width>448</width>
<height>112</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -140,6 +143,33 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QCheckBox" name="cb_follow_symlinks">
<property name="toolTip">
<string>Follow symbolic links when parsing files</string>
</property>
<property name="text">
<string>Follow symlinks</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
Expand Down
8 changes: 7 additions & 1 deletion tree_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def tree_parser(
directories_to_parse_queue: multiprocessing.Queue,
parsed_queue: multiprocessing.Queue,
skipped_entries_abs: List[str],
follow_symlinks: bool,
stats_tree_parsed_dirs: multiprocessing.Value,
stats_tree_parsed_files: multiprocessing.Value,
control_value: multiprocessing.Value or None = None,
Expand All @@ -55,6 +56,7 @@ def tree_parser(
parsed_queue (multiprocessing.Queue): parsing results as tuples
(relative path, root dir path, PATH_..., is empty directory)
skipped_entries_abs (List[str]): list of normalized absolute paths to skip,
follow_symlinks (bool): True to follow symlinks, false to ignore them
stats_tree_parsed_dirs (multiprocessing.Value): counter of total successfully parsed directories
stats_tree_parsed_files (multiprocessing.Value): counter of total successfully parsed files
control_value (multiprocessing.Value or None, optional): value (int) to pause / cancel process
Expand Down Expand Up @@ -135,7 +137,7 @@ def tree_parser(
while True:
# Try to get next path
try:
dir_or_file = next(parent_dir_abs_generator)
dir_or_file = next(parent_dir_abs_generator).is_symlink

# No more paths -> exit
except StopIteration:
Expand All @@ -149,6 +151,10 @@ def tree_parser(

# Parse it
try:
# Ignore symlinks
if dir_or_file.is_symlink() and not follow_symlinks:
continue

# Ignore if found in skipped paths
if os.path.normpath(str(dir_or_file)) in skipped_entries_abs:
continue
Expand Down

0 comments on commit 584ee34

Please sign in to comment.