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: symlinks handling #3298

Merged
merged 61 commits into from
Nov 14, 2024
Merged

fix: symlinks handling #3298

merged 61 commits into from
Nov 14, 2024

Conversation

2ZeroSix
Copy link
Contributor

@2ZeroSix 2ZeroSix commented Feb 1, 2022

fixes: #3143

@jonasfj
Copy link
Member

jonasfj commented Feb 1, 2022

I'm a bit unsure if we want to support this, how does it handle cycles?
What is the need for symlink directories?

Might it not be better to just ask advanced users to copy files if they need to include them in multiple locations. They can wrap their dart pub publish command with a bash script living in tool/ -- it's ugly, but how many people actually need this?

@2ZeroSix
Copy link
Contributor Author

2ZeroSix commented Feb 1, 2022

It’s common use case for macOS/iOS plug-ins, third party libraries in ffi plugins etc

In our case it forces us to remove directory with symlink to common scripts before publish

pubignore also does not solve it since this check is done prior to application of ignore rules

@2ZeroSix
Copy link
Contributor Author

2ZeroSix commented Feb 1, 2022

  • added test for cycles
  • fixed wrongly appended / to path consisted of single delimiter

The only failing test should be one which ensures lish is failing on package with symlink to directory.
This seems to be a regression and was introduced somewhere between flutter 2.5+ and 2.8- (dart 2.12 and 2.15)

Previous behavior (pub bundled in dart 2.12 and behavior in current PR):

  • pub archives all filtered files in tar.gz

  • consumer receives them as separate files after unpacking of tar.gz

  • so, there is no OS-dependant problems for consumer and no headache for package developer

Current behavior:

  • pub throws on any (even ignored) directory symlink beneath package directory
  • package developers should apply workarounds to their pipelines
  • consumers doesn't see any difference

If you insist this is expected behavior: I could try to move the check after resolving of ignored files and allow only ignored directory symlinks

@2ZeroSix
Copy link
Contributor Author

2ZeroSix commented Feb 3, 2022

Hmm, it seems that in windows it fails to list dirrectory with loops in symlinks

It differs from what is done on posix-like systems

02:34 +32 -1: test/package_list_files_test.dart: throws on symlink cycles
02:34 +32 -2: test/package_list_files_test.dart: throws on symlink cycles [E]
  Expected: throws <Instance of 'DataException'> with `message`: contains 'Pub does not support publishing packages with non-resolving symlink:'
    Actual: <Closure: () => List<String>>
     Which: threw FileSystemException:<FileSystemException: Directory listing failed, path = 'C:\Users\runneradmin\AppData\Local\Temp\dart_test_5e4ddcd9\myapp\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\subdir\symlink\*' (OS Error: The system cannot find the path specified.
                  , errno = 3)>
            stack dart:io                                   _Directory.listSync
                  package:pub/src/package.dart 248:48       Package.listFiles.<fn>
                  package:pub/src/ignore.dart 291:28        Ignore.listFiles
                  package:pub/src/package.dart 245:19       Package.listFiles
                  test\package_list_files_test.dart 115:30  main.<fn>.<fn>
                  package:test_api                          expect
                  test\package_list_files_test.dart 114:5   main.<fn>
                  
            which is not an instance of 'DataException'
  
  package:test_api                         expect
  test\package_list_files_test.dart 114:5  main.<fn>

lib/src/package.dart Outdated Show resolved Hide resolved
lib/src/package.dart Outdated Show resolved Hide resolved
@sigurdm
Copy link
Contributor

sigurdm commented Feb 10, 2022

Besides the cycle-handling this is looking quite good!

@2ZeroSix
Copy link
Contributor Author

jfyi: I had no time to reslove windows-related bugs lately, will continue in a few days

@sigurdm
Copy link
Contributor

sigurdm commented Oct 22, 2024

Hmm - seems the CI doesn't agree quite with my research.

On mac it seems contents of sufficiently nested directories is not listed. And on windows sufficiently nested links exists as Link but not as a Directory...

@spydon
Copy link

spydon commented Oct 22, 2024

Hmm - seems the CI doesn't agree quite with my research.

On mac it seems contents of sufficiently nested directories is not listed. And on windows sufficiently nested links exists as Link but not as a Directory...

Does that matter if it is documented? It would still work for all use cases where everything is set up correctly right?

@sigurdm
Copy link
Contributor

sigurdm commented Oct 24, 2024

Yeah - perhaps we don't need to care that much about symlink cycles. If you have them, you kind of set yourself up for trouble...

@sigurdm
Copy link
Contributor

sigurdm commented Oct 29, 2024

@jonasfj I reinstated some symlink detection. I think™ this works.

  • For every visited directory x, it resolves canonicalize(x) to x'.
  • Then for every parent of canonicalize(x), p:
    • it resolves p to p'. If x' equals p' it reports a cycle.

Could you do a sanity check?

Copy link
Member

@jonasfj jonasfj left a comment

Choose a reason for hiding this comment

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

I think this will work.

lib/src/package.dart Outdated Show resolved Hide resolved
test/package_list_files_test.dart Outdated Show resolved Hide resolved
test/package_list_files_test.dart Outdated Show resolved Hide resolved
test/package_list_files_test.dart Show resolved Hide resolved
@sigurdm sigurdm requested a review from jonasfj October 31, 2024 13:21
test/link_descriptor.dart Outdated Show resolved Hide resolved
test/link_descriptor.dart Outdated Show resolved Hide resolved
@sigurdm sigurdm requested review from jonasfj and szakarias November 1, 2024 13:27
test/package_list_files_test.dart Show resolved Hide resolved
test/validator/gitignore_test.dart Show resolved Hide resolved
@sigurdm sigurdm merged commit 8b349a8 into dart-lang:master Nov 14, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pub does not support publishing packages with directory symlinks
6 participants