Skip to content

Commit

Permalink
Merge pull request #67 from fls-bioinformatics-core/dont-archive-unre…
Browse files Browse the repository at this point in the history
…adable-dir

'archive' command refuses if source has unreadable content (even with --force)
  • Loading branch information
pjbriggs authored Jan 24, 2025
2 parents 64b3579 + 2fa2413 commit 20e7ade
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ngsarchiver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def main(argv=None):
help="check for and warn about potential "
"issues; don't perform archiving")
parser_archive.add_argument('--force',action='store_true',
help="ignore issues and perform "
"archiving anyway (may result in "
"incomplete or problematic archive)")
help="ignore issues with links, UIDS and/or "
"archive volume sizes and perform archiving "
"anyway")

# 'copy' command
parser_copy = s.add_parser('copy',
Expand Down Expand Up @@ -398,18 +398,22 @@ def main(argv=None):
print(f"-- unknown UIDs : {format_bool(has_unknown_uids)}")
has_hard_linked_files = d.has_hard_linked_files
print(f"-- hard linked files : {format_bool(has_hard_linked_files)}")
if not is_readable:
msg = "Unreadable files and/or directories detected"
logger.critical(msg)
if args.check:
check_status = 1
else:
return CLIStatus.ERROR
if has_external_symlinks or \
has_broken_symlinks or \
not is_readable or \
has_unknown_uids:
msg = "Readability, symlink and/or UID issues detected"
msg = "Symlink and/or UID issues detected"
if args.check:
logger.warning(msg)
check_status = 1
elif args.force:
msg += " (ignored"
if not is_readable:
msg += "; unreadable files will be omitted"
if has_external_symlinks or \
has_broken_symlinks or \
has_unresolvable_symlinks:
Expand Down
21 changes: 21 additions & 0 deletions ngsarchiver/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,27 @@ def test_archive_already_exists(self):
self.assertEqual(main(['archive',example_dir.path]),
CLIStatus.ERROR)

def test_archive_refuse_if_source_has_unreadable_files(self):
"""
CLI: test the 'archive' command refuses for source with unreadable file (even using --force)
"""
# Make example directory to archive
example_dir = UnittestDir(os.path.join(self.wd,"example"))
example_dir.add("ex1.txt",type="file",content="example 1")
example_dir.add("subdir1/ex2.txt",type="file")
example_dir.create()
try:
# Make one of the files unreadable
os.chmod(os.path.join(example_dir.path, "ex1.txt"), 0o000)
# Check archiving refuses
self.assertEqual(main(['archive',example_dir.path]),
CLIStatus.ERROR)
# Check archiving refuses even with --force
self.assertEqual(main(['archive', '--force', example_dir.path]),
CLIStatus.ERROR)
finally:
os.chmod(os.path.join(example_dir.path, "ex1.txt"), 0o644)

def test_archive_refuse_compressed_archive_directory(self):
"""
CLI: test the 'archive' command refuses for a compressed archive
Expand Down

0 comments on commit 20e7ade

Please sign in to comment.