Skip to content

Conversation

@alquerci
Copy link

@alquerci alquerci commented May 20, 2016

Hello,

Reply to #1311

It's an answer of https://github.com/pypa/pip/pull/1311/files#r7640350

If a project contains true NTFS symlinks it require elevated privileges indeed (source: @docs.python: os.symlink and @Wikipedia: NTFS_symbolic_link)

Fix shutil.copytree for py3 when a symlink points to a directory

Prevent circular symbolic links

Add test with circular symbolic links

revert f579c17

It should be also update tests.lib.path.Path.copytree method (e.g. git revert 99a4f6f) but it will add a dependency to pip.util module.

All comments are welcome


This was migrated from #1329 to reparent it to the master branch. Please see original pull request for any previous discussion.

  • rebase it against master

This change is Reviewable

@alquerci
Copy link
Author

Seems has been fixed since Python 3.5 travis build and py3.5 source.

@alquerci alquerci changed the title [WIP] Added the possibility to follow symlinks on copytree also for py3 Added the possibility to follow symlinks on copytree also for py3 May 21, 2016
@dstufft
Copy link
Member

dstufft commented May 26, 2016

You said this has been fixed- Does that mean this PR is no longer needed? Or that it's needed for Python's older then 3.5?

@alquerci
Copy link
Author

Does that mean this PR is no longer needed?

no, it keep needed, details are follow:

  • 233bbba Fixed shutil.copytree for py3 when a symlink points to a directory
    Fix for python version > 2 and < 3.5
  • 145e0b6 Ignored circular symbolic links when copytree
    Fix for all Python versions

cc @dstufft

@xavfernandez xavfernandez reopened this Jan 6, 2017
@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Apr 1, 2017
@pradyunsg
Copy link
Member

Hi!

@alquerci Could you by any chance fix the conflicts in this PR?

Sidenote: The tests seem to be failing on AppVeyor.

@pradyunsg pradyunsg added the S: awaiting response Waiting for a response/more information label Aug 21, 2017
@alquerci
Copy link
Author

Hello @pradyunsg

I will start to do it by tomorrow.

@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Aug 26, 2017
@alquerci
Copy link
Author

alquerci commented Aug 26, 2017

@pradyunsg All type of fixes are done (conflicts, lints, news).

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

Mostly just minor nits and a few misc questions.

I've not checked the functionality of the PR since I haven't read the previous discussions on this PR yet. :)

@@ -0,0 +1,3 @@
1. Revert previous fix that disable symlinks dereference.
Copy link
Member

Choose a reason for hiding this comment

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

Please don't have a numbered list here. The news fragments get aggregated into a list. This would result in a list containing a list - nobody wants that in NEWS. :P

Having a commit message style summary line followed by a small passage describing the change would probably be a better format. :)


This suggests to me that this PR is doing multiple things at the same time; if so, is it possible to split them?

os.symlink(linkto, dst)
return dst
except OSError:
# catch the OSError when the os.symlink function is called
Copy link
Member

Choose a reason for hiding this comment

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

nit: Catch

'Circular reference detected in "%s" ("%s" > "%s").'
'' % (resources[0], '" > "'.join(resources), resources[0]),
)
PipError.__init__(self, message)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Use super(CircularSymlinkException, self).__init__(message)

def validate_path(path):
"""Detect circular symbolic link
@raise CircularSymlinkException: When a symlink loop was found
Copy link
Member

Choose a reason for hiding this comment

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

nit: Use plain English; don't tag with @raise since that isn't something consistent with the rest of the codebase.

def copytree_ignore_callback(src, names):
"""Ignore circular symbolic links
@return: set of ignores names
Copy link
Member

Choose a reason for hiding this comment

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

nit: Use plain English; as above.



def copytree(source, location, symlinks=False):
return compat.copytree(
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to have a docstring here describing why we don't simply reuse shutil.copytree.

)


def copytree_ignore_callback(src, names):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make this _copytree_ignore_callback?

finally:
os.unlink(symbar_link)

@pytest.mark.skipif(
Copy link
Member

Choose a reason for hiding this comment

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

nit: You're using the same decorator in multiple places; you can simply make it into a module level underscored variable and decorate functions with it.

needs_os_symlink = pytest.mark.skipif(not hasattr(os, "symlink"), reason="requires os.symlink")

import tarfile
import zipfile

# For copytree as when using from an import exception is thrown.
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, what are you seeing?

os.symlink(foo_file, symfoo_link)
validate_path(symfoo_link)
except OSError:
return
Copy link
Member

Choose a reason for hiding this comment

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

Skip the test or make it fail if you come inside the except; maybe don't actually catch it?

Same for later cases as well.

@pradyunsg
Copy link
Member

Thanks for updating this @alquerci! ^.^

@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Sep 1, 2017
@pradyunsg
Copy link
Member

@alquerci Could you fix the conflicts in this PR; again?

@pradyunsg
Copy link
Member

Closing due to lack of a response.

@pradyunsg pradyunsg removed the S: awaiting response Waiting for a response/more information label Nov 4, 2017
@pradyunsg pradyunsg closed this Nov 4, 2017
@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
@pradyunsg pradyunsg removed the needs rebase or merge PR has conflicts with current master label Apr 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

auto-locked Outdated issues that have been locked by automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants