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

dart:io file api doesn't work with long file names on windows #42416

Closed
sigurdm opened this issue Jun 19, 2020 · 3 comments
Closed

dart:io file api doesn't work with long file names on windows #42416

sigurdm opened this issue Jun 19, 2020 · 3 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io

Comments

@sigurdm
Copy link
Contributor

sigurdm commented Jun 19, 2020

Dart version: Dart VM version: 2.8.4 (stable) (Wed Jun 3 12:26:04 2020 +0200) on "windows_x64"
Windows 10 Enterprise

Reproduction:

import 'dart:io';

void main() {
 File('${'nana' * 100}').writeAsStringSync('hi');
}

Prints:

Unhandled exception:
FileSystemException: Cannot open file, path = 'nananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananana' (OS Error: The system cannot find the path specified.
, errno = 3)
#0      _File.throwIfError (dart:io/file_impl.dart:645:7)
#1      _File.openSync (dart:io/file_impl.dart:489:5)
#2      _File.writeAsBytesSync (dart:io/file_impl.dart:614:31)
#3      _File.writeAsStringSync (dart:io/file_impl.dart:638:5)
#4      main (file:///C:/Users/sigurdm/pana/bin/long_names.dart:5:25)
#5      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

The program works if the name is shorter.

The same happens if I try deleting a directory containing files with long names with Directory.delete(recursive:true);. (That's how I stumbled into this).

According to https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation there should be ways of enabling long paths on windows 10.

@keertip keertip added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Jun 19, 2020
@zichangg
Copy link
Contributor

I'm looking at the APIs and try to add to our VM.

I think your example is not going to work. The file name itself (4 * 100) has exceeded the limit.

This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters).

@sigurdm I'm trying to experiment on my Windows machine. How did you enable the "long path"? I've modified the registry key and reboot my machine. But I'm still not able to create a file with path longer than MAX_PATH.

@sigurdm
Copy link
Contributor Author

sigurdm commented Jun 25, 2020

If you clone https://github.com/dart-lang/pana and run pub run test/end2end_test.dart it creates a filename too long to delete for dart (it will fail when deleting the temporary pub-cache from tearDownAll).
I believe that file is created by pub untar-ing files with too long names inside. (it uses 7z as a sub-process to untar on windows).

@zichangg
Copy link
Contributor

zichangg commented Sep 1, 2020

https://dart-review.googlesource.com/c/sdk/+/152736 is working in progress, which will enable the long path on Windows.

One problem with cl is Directory.current doesn't work with long path.

Another solution can be added in the future is to embed the manifest into dart.exe which enables long path. The drawback of this solution is that this isn't supported on earlier versions of Windows.

dart-bot pushed a commit that referenced this issue Sep 8, 2020
File APIs on Windows can now handle files and directories identified by
long paths (greater than 260 characters). For directory, the limit is
248.

Some restrictions from Windows:
1. The size limit for long path is 32,767 characters.
2. Each component separated by backslashes should not be more than 255
characters.

Reference: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation.

Note that `Directory.current` does not work with long path.

Bug: #42416
Change-Id: Ia1b4608d393fb36f1d843858c6f076f3c825dc83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152736
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Zichang Guo <zichangguo@google.com>
dart-bot pushed a commit that referenced this issue Sep 8, 2020
This reverts commit 08662f0.

Reason for revert: failure on pkg-win-release, https://dart-ci.appspot.com/log/pkg-win-release/unittest-asserts-release-win/12878/pkg/dartdev/test/commands/test_test

Original change's description:
> Enable long path on Windows
> 
> File APIs on Windows can now handle files and directories identified by
> long paths (greater than 260 characters). For directory, the limit is
> 248.
> 
> Some restrictions from Windows:
> 1. The size limit for long path is 32,767 characters.
> 2. Each component separated by backslashes should not be more than 255
> characters.
> 
> Reference: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation.
> 
> Note that `Directory.current` does not work with long path.
> 
> Bug: #42416
> Change-Id: Ia1b4608d393fb36f1d843858c6f076f3c825dc83
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152736
> Reviewed-by: Alexander Aprelev <aam@google.com>
> Commit-Queue: Zichang Guo <zichangguo@google.com>

TBR=aam@google.com,zra@google.com,zichangguo@google.com

Change-Id: If6701c887e616cd62f20faac43f601cfb53ed349
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: #42416
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162104
Reviewed-by: Zichang Guo <zichangguo@google.com>
Commit-Queue: Zichang Guo <zichangguo@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io
Projects
None yet
Development

No branches or pull requests

3 participants