Pub: Fetching dependencies via SSH fails on Windows because of colon in path

Created on 11 Jun 2020  路  5Comments  路  Source: dart-lang/pub

Environment

  • pub version or flutter pub version: Pub 2.9.0-14.0.dev.flutter-5c1376615e
  • OS version: Windows 10
  • Are you using the Chinese community mirror or a corporate firewall? No

Problem

We are hosting a commercial package on a private git repository which can only be accessed via SSH.
So we added it as a dependency in a legal form as described here: https://dart.dev/tools/pub/dependencies#git-packages
This works on macOS, but on Windows it gives this error when fetching the package:

PS C:\Users\tv\Development\skp-client> flutter pub get flutter_font_awesome_pro
Creation failed, path = 'C:\src\flutter\.pub-cache\git\cache\[email protected]:flutter-font-awesome-pro-b99638a73598d20b89a0eb2dcb75641be005e731' (OS Error: Der Verzeichnisname ist ung眉ltig.
, errno = 267)
Running "flutter pub get" in ....
pub get failed (66; , errno = 267))

The German error means that the cache directory name [email protected]:flutter-font-awesome-pro-b99638a73598d20b89a0eb2dcb75641be005e731 is invalid, which is true: You cannot have a : (colon) in a Windows directory name.

dependencies:
  # commercial version of font awesome icons
  flutter_font_awesome_pro:
    git: [email protected]:flutter-font-awesome-pro.git

Expected behavior

It would be better, if the directory name within the Pub Cache does not include illegal characters for Windows file systems.

Actual behavior

Pub Cache tries to store the fetched package in a path with an illegal character. In this case a colon.

All 5 comments

I guess we could url-encode the repo-name for storing in cache.

For handling backwards-compatibility for those characters that __are__ valid, but gets encoded, we could start by looking up for an existing directory with the not-encoded name, and rename if it exists.

@jonasfj WDYT?

I think we just need to tweak:
https://github.com/dart-lang/pub/blob/b239ada4b0f80cf4581be10251fa94b02689ef86/lib/src/source/git.dart#L575-L584

Such that we split at colon too... and strip all special characters if there is any. We could also just split at first the non-ascii character, and fallback to git if there is no characters left..

We concatenate with the hash of the full git URL anyways, so the human readable name is probably just to make the folder name decipherable to humans.

For handling backwards-compatibility for those characters that are valid, but gets encoded, we could start by looking up for an existing directory with the not-encoded name, and rename if it exists.

Do we need backwards-compatibility, if a newer version of pub get creates a new folder that should be fine, right?
Worse case we duplicate a few git repositories.

Worst case we duplicate a few git repositories.

I guess that also sucks....

Worst case we duplicate a few git repositories.
I guess that also sucks....

We duplicate whenever the repository name/url changes anyways.
But we could probably make it so that this only affects git-urls that contains special chars in the p.url.basename(...) of the url.

The bug here is really just that some of the human readable names we make include special chars that make unsuitable for use in paths. The fix only has to further sanitize the human readable names -- as far as I can see collisions isn't a concern as we suffixed with URL hash anyways.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DartBot picture DartBot  路  72Comments

kevmoo picture kevmoo  路  53Comments

sinadarvi picture sinadarvi  路  24Comments

crajygemer picture crajygemer  路  24Comments

goderbauer picture goderbauer  路  57Comments