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

feat: Check if Include folders/files do exists (in case they are removed) #1718

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f6bf5bc
Check if Include folders/files do exists (in case they are removed)
rafaelhdr May 9, 2024
d4556ca
Update CHANGES
rafaelhdr May 9, 2024
5f3a8c7
PEP8 convention
rafaelhdr May 9, 2024
e07d5a1
PEP8 convention
rafaelhdr May 9, 2024
ce4d761
PEP8 convention
rafaelhdr May 9, 2024
27fe2da
refactor code from review
rafaelhdr May 9, 2024
27ac817
PEP8 snake case
rafaelhdr May 9, 2024
4f36503
fixes missing self
rafaelhdr May 9, 2024
9cb8348
PEP8 snake convention
rafaelhdr May 9, 2024
7472f54
PEP8 blank lines
rafaelhdr May 9, 2024
287d129
Merge branch 'dev' into check-included-do-exists
buhtz May 10, 2024
5161ccd
Merge branch 'dev' into check-included-do-exists
buhtz May 12, 2024
45aa011
move warning about missing snapshots for after mounting
rafaelhdr May 20, 2024
c2941ba
display error message on include
rafaelhdr May 20, 2024
6668487
Merge remote-tracking branch 'bit/dev' into check-included-do-exists
rafaelhdr May 20, 2024
205ee49
Merge branch 'dev' into check-included-do-exists
buhtz Jun 18, 2024
03c1050
Merge branch 'dev' into check-included-do-exists
buhtz Jun 28, 2024
bb5969c
document and rename has_missing_includes
rafaelhdr Jul 26, 2024
5416356
Merge remote-tracking branch 'bit/dev' into check-included-do-exists
rafaelhdr Aug 4, 2024
42b5e06
Merge branch 'dev' into check-included-do-exists
buhtz Oct 3, 2024
1f9d888
Merge branch 'dev' into check-included-do-exists
buhtz Nov 28, 2024
3ac5526
Update common/snapshots.py
rafaelhdr Jan 7, 2025
8004348
Update qt/app.py
rafaelhdr Jan 7, 2025
31b7424
review fixes
Jan 7, 2025
7dd5b74
Merge remote-tracking branch 'bit-team/dev' into check-included-do-ex…
Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Version 1.5.2 (2024-08-06)
* Build(translation): Language helper script processing syntax checks on po-files

Version 1.5.1 (2024-07-27)
* Fix bug: Check if Include folders/files do exists (in case they are removed) (#1586) (@rafaelhdr)
Copy link
Member

Choose a reason for hiding this comment

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

You can move this entry up to the first section in the changelog.

* Fix: Use correct port to ping SSH Proxy (#1815)

Version 1.5.0 (2024-07-26)
Expand Down
37 changes: 37 additions & 0 deletions common/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,23 @@ def remove(self, sid):

return True

def _check_included_sources_exist_on_take_snapshot(self, config):
"""
Check if files and/or directories in the include list exist on the source.

If a file or directory does not exist, a warning message is logged.

Args:
cfg (config.Config): Config that should be used.
"""
missing = has_missing_includes(config.include())

if missing:
msg = ', '.join(missing)
msg = f'The following files/folders are missing: {msg}'
logger.warning(msg)
self.setTakeSnapshotMessage(1, msg)
buhtz marked this conversation as resolved.
Show resolved Hide resolved

# TODO Refactor: This functions is extremely difficult to understand:
# - Nested "if"s
# - Fuzzy names of classes, attributes and methods
Expand Down Expand Up @@ -804,6 +821,7 @@ def backup(self, force=False):
else:
self.config.setCurrentHashId(hash_id)

self._check_included_sources_exist_on_take_snapshot(self.config)
include_folders = self.config.include()

if not include_folders:
Expand Down Expand Up @@ -3163,6 +3181,25 @@ def lastSnapshot(cfg):
return sids[0]


def has_missing_includes(included):
"""
Check if there are missing files or folders in a snapshot.

Args:
included (list): list of tuples (item, info)

Returns:
tuple: (bool, str) where bool is ``True`` if there are
missing files or folders and str is a message
describing the missing files or folders
"""
not_found = []
for path, _ in included:
if not os.path.exists(path):
buhtz marked this conversation as resolved.
Show resolved Hide resolved
not_found.append(path)
return not_found


if __name__ == '__main__':
config = config.Config()
snapshots = Snapshots(config)
Expand Down
21 changes: 18 additions & 3 deletions qt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,12 +1286,27 @@ def updateTimeLine(self, refreshSnapshotsList=True):
item = self.timeLine.addSnapshot(sid)
self.timeLine.checkSelection()

def validate_on_take_snapshot(self):
buhtz marked this conversation as resolved.
Show resolved Hide resolved
missing = snapshots.has_missing_includes(self.config.include())
if missing:
msg_missing = '\n'.join(missing)
msg = _('The following directories are missing: {dirs} Do you want to proceed?'.format(
dirs=f'\n{msg_missing}\n\n'))
Comment on lines +1293 to +1294
Copy link
Member

@buhtz buhtz Jan 8, 2025

Choose a reason for hiding this comment

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

The format() need to be outside of the translatable string.

# Problematic code
_('foo {val}'.format(val='bar'))

# Good code
_('foo {val}').format(val='bar')

Don't worry, this translation stuff is complex.

Suggested change
msg = _('The following directories are missing: {dirs} Do you want to proceed?'.format(
dirs=f'\n{msg_missing}\n\n'))
msg = _('The following directories are missing: {dirs} Do you want to proceed?').format(
dirs=f'\n{msg_missing}\n\n')

answer = messagebox.warningYesNo(self, msg)
buhtz marked this conversation as resolved.
Show resolved Hide resolved
return answer == QMessageBox.StandardButton.Yes
return True

def btnTakeSnapshotClicked(self):
backintime.takeSnapshotAsync(self.config)
self.updateTakeSnapshot(True)
self._take_snapshot_clicked(checksum=False)

def btnTakeSnapshotChecksumClicked(self):
backintime.takeSnapshotAsync(self.config, checksum = True)
self._take_snapshot_clicked(checksum=True)

def _take_snapshot_clicked(self, checksum):
if not self.validate_on_take_snapshot():
return

backintime.takeSnapshotAsync(self.config, checksum=checksum)
self.updateTakeSnapshot(True)

def btnStopTakeSnapshotClicked(self):
Expand Down