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

fix: handle broken symbolic links that were listing as missing files #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion check_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,10 +961,15 @@ def check_manifest(source_tree='.', create=False, update=False,
ui.info_continue(": %d files and directories" % len(sdist_files))
version = extract_version_from_filename(sdist_filename)
existing_source_files = list(filter(os.path.exists, all_source_files))
missing_source_files = sorted(set(all_source_files) - set(existing_source_files))
existing_source_files_with_broken_symlinks = list(filter(os.path.lexists, all_source_files))
missing_source_files = sorted(set(all_source_files) - set(existing_source_files_with_broken_symlinks))
if missing_source_files:
ui.warning("some files listed as being under source control are missing:\n%s"
% format_list(missing_source_files))
broken_symlinks = set(existing_source_files_with_broken_symlinks) - set(existing_source_files)
if broken_symlinks:
ui.warning("some symbolic links listed as being under source control are pointing to missing files:\n%s"
% format_list(["%s -> %s (missing)" % (x, os.readlink(x)) for x in broken_symlinks]))
ui.info_begin("copying source files to a temporary directory")
with mkdtemp('-sources') as tempsourcedir:
copy_files(existing_source_files, tempsourcedir)
Expand Down
18 changes: 18 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1815,3 +1815,21 @@ def test_missing_source_files(self):
"some files listed as being under source control are missing:\n"
" missing.py",
sys.stderr.getvalue())

def test_broken_symbolic_link(self):
from check_manifest import check_manifest
self._create_repo_with_code()
os.symlink(os.path.join(self.tmpdir, "some-file"),
os.path.join(self.tmpdir, "some-symbolic-link"))
Comment on lines +1822 to +1823
Copy link
Owner

Choose a reason for hiding this comment

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

Seeing the Appveyor CI failure on Windows, I think

Suggested change
os.symlink(os.path.join(self.tmpdir, "some-file"),
os.path.join(self.tmpdir, "some-symbolic-link"))
os.symlink(os.path.join(self.tmpdir, "some-file"), "some-symbolic-link")

might work better ...

self._add_to_vcs('some-file')
self._add_to_vcs('some-symbolic-link')
self._add_to_vcs('MANIFEST.in')
with open(os.path.join(self.tmpdir, "MANIFEST.in"), "w") as f:
f.write("include some-symbolic-link\ninclude some-file\n")
self.assertTrue(check_manifest())
self._vcs._commit()
os.unlink('some-file')
check_manifest()
self.assertIn("some symbolic links listed as being under source control are pointing to missing files:\n"
f" some-symbolic-link -> {os.path.join(self.tmpdir, 'some-file')} (missing)",
Copy link
Owner

@mgedmin mgedmin Jun 27, 2023

Choose a reason for hiding this comment

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

... because then you might be able to use

Suggested change
f" some-symbolic-link -> {os.path.join(self.tmpdir, 'some-file')} (missing)",
" some-symbolic-link -> some-file (missing)",

here.

Of course, Windows being Windows, there's a chance that even relative symlinks will be converted into those weird absolute UNC paths, in which case plan B is

# On Windows os.readlink() returns weird UNC paths so we cannot hardcode os.path.join(self.tmpdir, "...") here
link_target = os.readlink(os.path.join(self.tmpdir, "some-symbolic-link"))

followed by using

Suggested change
f" some-symbolic-link -> {os.path.join(self.tmpdir, 'some-file')} (missing)",
f" some-symbolic-link -> {link_target} (missing)",

here.

sys.stderr.getvalue())