Skip to content

Commit f8fbefd

Browse files
zichanggcommit-bot@chromium.org
authored andcommitted
Revert "Enable long path on Windows"
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: dart-lang/sdk#42416 > Change-Id: Ia1b4608d393fb36f1d843858c6f076f3c825dc83 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152736 > Reviewed-by: Alexander Aprelev <[email protected]> > Commit-Queue: Zichang Guo <[email protected]> [email protected],[email protected],[email protected] Change-Id: If6701c887e616cd62f20faac43f601cfb53ed349 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: dart-lang/sdk#42416 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162104 Reviewed-by: Zichang Guo <[email protected]> Commit-Queue: Zichang Guo <[email protected]>
1 parent b8fa8c9 commit f8fbefd

11 files changed

+65
-777
lines changed

CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,9 @@ applications (issue [flutter/flutter#63038][]).
130130
* [Abstract Unix Domain Socket][] is supported on Linux/Android now. Using an
131131
`InternetAddress` with `address` starting with '@' and type being
132132
`InternetAddressType.Unix` will create an abstract Unix Domain Socket.
133-
* On Windows, file APIs can now handle files and directories identified by
134-
long paths (greater than 260 characters). It complies with all restrictions
135-
from [Long Path on Windows][]. Note that `Directory.current` does not work
136-
with long path.
137133

138134
[#42006]: https://github.com/dart-lang/sdk/issues/42006
139135
[Abstract Unix Domain Socket]: http://man7.org/linux/man-pages/man7/unix.7.html
140-
[Long Path on Windows]: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
141136

142137
#### `dart:html`
143138

runtime/bin/builtin_impl_sources.gni

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ builtin_impl_sources = [
4545
"file_macos.cc",
4646
"file_support.cc",
4747
"file_win.cc",
48-
"file_win.h",
4948
"io_buffer.cc",
5049
"io_buffer.h",
5150
"isolate_data.cc",

runtime/bin/directory_win.cc

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "bin/crypto.h"
1414
#include "bin/dartutils.h"
1515
#include "bin/file.h"
16-
#include "bin/file_win.h"
1716
#include "bin/namespace.h"
1817
#include "bin/utils.h"
1918
#include "bin/utils_win.h"
@@ -22,6 +21,8 @@
2221

2322
#undef DeleteFile
2423

24+
#define MAX_LONG_PATH 32767
25+
2526
namespace dart {
2627
namespace bin {
2728

@@ -277,47 +278,41 @@ static bool DeleteEntry(LPWIN32_FIND_DATAW find_file_data, PathBuffer* path) {
277278
}
278279

279280
static bool DeleteRecursively(PathBuffer* path) {
280-
PathBuffer prefixed_path;
281-
if (!prefixed_path.Add(PrefixLongDirectoryPath(path->AsScopedString()))) {
282-
return false;
283-
}
284-
285-
DWORD attributes = GetFileAttributesW(prefixed_path.AsStringW());
281+
DWORD attributes = GetFileAttributesW(path->AsStringW());
286282
if (attributes == INVALID_FILE_ATTRIBUTES) {
287283
return false;
288284
}
289285
// If the directory is a junction, it's pointing to some other place in the
290286
// filesystem that we do not want to recurse into.
291287
if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
292288
// Just delete the junction itself.
293-
return RemoveDirectoryW(prefixed_path.AsStringW()) != 0;
289+
return RemoveDirectoryW(path->AsStringW()) != 0;
294290
}
295291
// If it's a file, remove it directly.
296292
if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
297-
return DeleteFile(L"", &prefixed_path);
293+
return DeleteFile(L"", path);
298294
}
299295

300-
if (!prefixed_path.AddW(L"\\*")) {
296+
if (!path->AddW(L"\\*")) {
301297
return false;
302298
}
303299

304300
WIN32_FIND_DATAW find_file_data;
305-
HANDLE find_handle =
306-
FindFirstFileW(prefixed_path.AsStringW(), &find_file_data);
301+
HANDLE find_handle = FindFirstFileW(path->AsStringW(), &find_file_data);
307302

308303
if (find_handle == INVALID_HANDLE_VALUE) {
309304
return false;
310305
}
311306

312307
// Adjust the path by removing the '*' used for the search.
313-
int path_length = prefixed_path.length() - 1;
314-
prefixed_path.Reset(path_length);
308+
int path_length = path->length() - 1;
309+
path->Reset(path_length);
315310

316311
do {
317-
if (!DeleteEntry(&find_file_data, &prefixed_path)) {
312+
if (!DeleteEntry(&find_file_data, path)) {
318313
break;
319314
}
320-
prefixed_path.Reset(path_length); // DeleteEntry adds to the path.
315+
path->Reset(path_length); // DeleteEntry adds to the path.
321316
} while (FindNextFileW(find_handle, &find_file_data) != 0);
322317

323318
DWORD last_error = GetLastError();
@@ -329,9 +324,8 @@ static bool DeleteRecursively(PathBuffer* path) {
329324
return false;
330325
}
331326
// All content deleted succesfully, try to delete directory.
332-
prefixed_path.Reset(path_length -
333-
1); // Drop the "\" from the end of the path.
334-
return RemoveDirectoryW(prefixed_path.AsStringW()) != 0;
327+
path->Reset(path_length - 1); // Drop the "\" from the end of the path.
328+
return RemoveDirectoryW(path->AsStringW()) != 0;
335329
}
336330

337331
static Directory::ExistsResult ExistsHelper(const wchar_t* dir_name) {
@@ -355,8 +349,7 @@ static Directory::ExistsResult ExistsHelper(const wchar_t* dir_name) {
355349

356350
Directory::ExistsResult Directory::Exists(Namespace* namespc,
357351
const char* dir_name) {
358-
const char* prefixed_dir_name = PrefixLongDirectoryPath(dir_name);
359-
Utf8ToWideScope system_name(prefixed_dir_name);
352+
Utf8ToWideScope system_name(dir_name);
360353
return ExistsHelper(system_name.wide());
361354
}
362355

@@ -376,8 +369,7 @@ char* Directory::CurrentNoScope() {
376369
}
377370

378371
bool Directory::Create(Namespace* namespc, const char* dir_name) {
379-
const char* prefixed_dir_name = PrefixLongDirectoryPath(dir_name);
380-
Utf8ToWideScope system_name(prefixed_dir_name);
372+
Utf8ToWideScope system_name(dir_name);
381373
int create_status = CreateDirectoryW(system_name.wide(), NULL);
382374
// If the directory already existed, treat it as a success.
383375
if ((create_status == 0) && (GetLastError() == ERROR_ALREADY_EXISTS) &&
@@ -483,11 +475,10 @@ const char* Directory::CreateTemp(Namespace* namespc, const char* prefix) {
483475
bool Directory::Delete(Namespace* namespc,
484476
const char* dir_name,
485477
bool recursive) {
486-
const char* prefixed_dir_name = PrefixLongDirectoryPath(dir_name);
487478
bool result = false;
488-
Utf8ToWideScope system_dir_name(prefixed_dir_name);
479+
Utf8ToWideScope system_dir_name(dir_name);
489480
if (!recursive) {
490-
if (File::GetType(namespc, prefixed_dir_name, true) == File::kIsDirectory) {
481+
if (File::GetType(namespc, dir_name, true) == File::kIsDirectory) {
491482
result = (RemoveDirectoryW(system_dir_name.wide()) != 0);
492483
} else {
493484
SetLastError(ERROR_FILE_NOT_FOUND);
@@ -504,20 +495,18 @@ bool Directory::Delete(Namespace* namespc,
504495
bool Directory::Rename(Namespace* namespc,
505496
const char* path,
506497
const char* new_path) {
507-
const char* prefixed_dir = PrefixLongDirectoryPath(path);
508-
Utf8ToWideScope system_path(prefixed_dir);
498+
Utf8ToWideScope system_path(path);
499+
Utf8ToWideScope system_new_path(new_path);
509500
ExistsResult exists = ExistsHelper(system_path.wide());
510501
if (exists != EXISTS) {
511502
return false;
512503
}
513-
const char* prefixed_new_dir = PrefixLongDirectoryPath(new_path);
514-
Utf8ToWideScope system_new_path(prefixed_new_dir);
515504
ExistsResult new_exists = ExistsHelper(system_new_path.wide());
516505
// MoveFile does not allow replacing existing directories. Therefore,
517506
// if the new_path is currently a directory we need to delete it
518507
// first.
519508
if (new_exists == EXISTS) {
520-
bool success = Delete(namespc, prefixed_new_dir, true);
509+
bool success = Delete(namespc, new_path, true);
521510
if (!success) {
522511
return false;
523512
}

0 commit comments

Comments
 (0)