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