13
13
#include " bin/crypto.h"
14
14
#include " bin/dartutils.h"
15
15
#include " bin/file.h"
16
+ #include " bin/file_win.h"
16
17
#include " bin/namespace.h"
17
18
#include " bin/utils.h"
18
19
#include " bin/utils_win.h"
21
22
22
23
#undef DeleteFile
23
24
24
- #define MAX_LONG_PATH 32767
25
-
26
25
namespace dart {
27
26
namespace bin {
28
27
@@ -278,41 +277,47 @@ static bool DeleteEntry(LPWIN32_FIND_DATAW find_file_data, PathBuffer* path) {
278
277
}
279
278
280
279
static bool DeleteRecursively (PathBuffer* path) {
281
- DWORD attributes = GetFileAttributesW (path->AsStringW ());
280
+ PathBuffer prefixed_path;
281
+ if (!prefixed_path.Add (PrefixLongDirectoryPath (path->AsScopedString ()))) {
282
+ return false ;
283
+ }
284
+
285
+ DWORD attributes = GetFileAttributesW (prefixed_path.AsStringW ());
282
286
if (attributes == INVALID_FILE_ATTRIBUTES) {
283
287
return false ;
284
288
}
285
289
// If the directory is a junction, it's pointing to some other place in the
286
290
// filesystem that we do not want to recurse into.
287
291
if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0 ) {
288
292
// Just delete the junction itself.
289
- return RemoveDirectoryW (path-> AsStringW ()) != 0 ;
293
+ return RemoveDirectoryW (prefixed_path. AsStringW ()) != 0 ;
290
294
}
291
295
// If it's a file, remove it directly.
292
296
if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0 ) {
293
- return DeleteFile (L" " , path );
297
+ return DeleteFile (L" " , &prefixed_path );
294
298
}
295
299
296
- if (!path-> AddW (L" \\ *" )) {
300
+ if (!prefixed_path. AddW (L" \\ *" )) {
297
301
return false ;
298
302
}
299
303
300
304
WIN32_FIND_DATAW find_file_data;
301
- HANDLE find_handle = FindFirstFileW (path->AsStringW (), &find_file_data);
305
+ HANDLE find_handle =
306
+ FindFirstFileW (prefixed_path.AsStringW (), &find_file_data);
302
307
303
308
if (find_handle == INVALID_HANDLE_VALUE) {
304
309
return false ;
305
310
}
306
311
307
312
// Adjust the path by removing the '*' used for the search.
308
- int path_length = path-> length () - 1 ;
309
- path-> Reset (path_length);
313
+ int path_length = prefixed_path. length () - 1 ;
314
+ prefixed_path. Reset (path_length);
310
315
311
316
do {
312
- if (!DeleteEntry (&find_file_data, path )) {
317
+ if (!DeleteEntry (&find_file_data, &prefixed_path )) {
313
318
break ;
314
319
}
315
- path-> Reset (path_length); // DeleteEntry adds to the path.
320
+ prefixed_path. Reset (path_length); // DeleteEntry adds to the path.
316
321
} while (FindNextFileW (find_handle, &find_file_data) != 0 );
317
322
318
323
DWORD last_error = GetLastError ();
@@ -324,8 +329,9 @@ static bool DeleteRecursively(PathBuffer* path) {
324
329
return false ;
325
330
}
326
331
// All content deleted succesfully, try to delete directory.
327
- path->Reset (path_length - 1 ); // Drop the "\" from the end of the path.
328
- return RemoveDirectoryW (path->AsStringW ()) != 0 ;
332
+ prefixed_path.Reset (path_length -
333
+ 1 ); // Drop the "\" from the end of the path.
334
+ return RemoveDirectoryW (prefixed_path.AsStringW ()) != 0 ;
329
335
}
330
336
331
337
static Directory::ExistsResult ExistsHelper (const wchar_t * dir_name) {
@@ -349,7 +355,8 @@ static Directory::ExistsResult ExistsHelper(const wchar_t* dir_name) {
349
355
350
356
Directory::ExistsResult Directory::Exists (Namespace* namespc,
351
357
const char * dir_name) {
352
- Utf8ToWideScope system_name (dir_name);
358
+ const char * prefixed_dir_name = PrefixLongDirectoryPath (dir_name);
359
+ Utf8ToWideScope system_name (prefixed_dir_name);
353
360
return ExistsHelper (system_name.wide ());
354
361
}
355
362
@@ -369,7 +376,8 @@ char* Directory::CurrentNoScope() {
369
376
}
370
377
371
378
bool Directory::Create (Namespace* namespc, const char * dir_name) {
372
- Utf8ToWideScope system_name (dir_name);
379
+ const char * prefixed_dir_name = PrefixLongDirectoryPath (dir_name);
380
+ Utf8ToWideScope system_name (prefixed_dir_name);
373
381
int create_status = CreateDirectoryW (system_name.wide (), NULL );
374
382
// If the directory already existed, treat it as a success.
375
383
if ((create_status == 0 ) && (GetLastError () == ERROR_ALREADY_EXISTS) &&
@@ -475,10 +483,11 @@ const char* Directory::CreateTemp(Namespace* namespc, const char* prefix) {
475
483
bool Directory::Delete (Namespace* namespc,
476
484
const char * dir_name,
477
485
bool recursive) {
486
+ const char * prefixed_dir_name = PrefixLongDirectoryPath (dir_name);
478
487
bool result = false ;
479
- Utf8ToWideScope system_dir_name (dir_name );
488
+ Utf8ToWideScope system_dir_name (prefixed_dir_name );
480
489
if (!recursive) {
481
- if (File::GetType (namespc, dir_name , true ) == File::kIsDirectory ) {
490
+ if (File::GetType (namespc, prefixed_dir_name , true ) == File::kIsDirectory ) {
482
491
result = (RemoveDirectoryW (system_dir_name.wide ()) != 0 );
483
492
} else {
484
493
SetLastError (ERROR_FILE_NOT_FOUND);
@@ -495,18 +504,20 @@ bool Directory::Delete(Namespace* namespc,
495
504
bool Directory::Rename (Namespace* namespc,
496
505
const char * path,
497
506
const char * new_path) {
498
- Utf8ToWideScope system_path (path);
499
- Utf8ToWideScope system_new_path (new_path );
507
+ const char * prefixed_dir = PrefixLongDirectoryPath (path);
508
+ Utf8ToWideScope system_path (prefixed_dir );
500
509
ExistsResult exists = ExistsHelper (system_path.wide ());
501
510
if (exists != EXISTS) {
502
511
return false ;
503
512
}
513
+ const char * prefixed_new_dir = PrefixLongDirectoryPath (new_path);
514
+ Utf8ToWideScope system_new_path (prefixed_new_dir);
504
515
ExistsResult new_exists = ExistsHelper (system_new_path.wide ());
505
516
// MoveFile does not allow replacing existing directories. Therefore,
506
517
// if the new_path is currently a directory we need to delete it
507
518
// first.
508
519
if (new_exists == EXISTS) {
509
- bool success = Delete (namespc, new_path , true );
520
+ bool success = Delete (namespc, prefixed_new_dir , true );
510
521
if (!success) {
511
522
return false ;
512
523
}
0 commit comments