OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <fcntl.h> // NOLINT | 10 #include <fcntl.h> // NOLINT |
11 #include <io.h> // NOLINT | 11 #include <io.h> // NOLINT |
12 #include <stdio.h> // NOLINT | 12 #include <stdio.h> // NOLINT |
13 #include <string.h> // NOLINT | 13 #include <string.h> // NOLINT |
14 #include <sys/stat.h> // NOLINT | 14 #include <sys/stat.h> // NOLINT |
15 #include <WinIoCtl.h> // NOLINT | 15 #include <WinIoCtl.h> // NOLINT |
16 | 16 |
17 #include "bin/builtin.h" | 17 #include "bin/builtin.h" |
18 #include "bin/log.h" | 18 #include "bin/log.h" |
19 #include "bin/utils.h" | 19 #include "bin/utils.h" |
| 20 #include "bin/utils_win.h" |
20 #include "platform/utils.h" | 21 #include "platform/utils.h" |
21 | 22 |
22 | 23 |
23 namespace dart { | 24 namespace dart { |
24 namespace bin { | 25 namespace bin { |
25 | 26 |
26 class FileHandle { | 27 class FileHandle { |
27 public: | 28 public: |
28 explicit FileHandle(int fd) : fd_(fd) { } | 29 explicit FileHandle(int fd) : fd_(fd) { } |
29 ~FileHandle() { } | 30 ~FileHandle() { } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ASSERT((mode & kWriteOnly) == 0); | 161 ASSERT((mode & kWriteOnly) == 0); |
161 flags = (O_RDWR | O_CREAT | O_BINARY | O_NOINHERIT); | 162 flags = (O_RDWR | O_CREAT | O_BINARY | O_NOINHERIT); |
162 } | 163 } |
163 if ((mode & kWriteOnly) != 0) { | 164 if ((mode & kWriteOnly) != 0) { |
164 ASSERT((mode & kWrite) == 0); | 165 ASSERT((mode & kWrite) == 0); |
165 flags = (O_WRONLY | O_CREAT | O_BINARY | O_NOINHERIT); | 166 flags = (O_WRONLY | O_CREAT | O_BINARY | O_NOINHERIT); |
166 } | 167 } |
167 if ((mode & kTruncate) != 0) { | 168 if ((mode & kTruncate) != 0) { |
168 flags = flags | O_TRUNC; | 169 flags = flags | O_TRUNC; |
169 } | 170 } |
170 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 171 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(name); |
171 int fd = _wopen(system_name, flags, 0666); | 172 int fd = _wopen(system_name, flags, 0666); |
172 free(const_cast<wchar_t*>(system_name)); | 173 free(const_cast<wchar_t*>(system_name)); |
173 if (fd < 0) { | 174 if (fd < 0) { |
174 return NULL; | 175 return NULL; |
175 } | 176 } |
176 if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) || | 177 if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) || |
177 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { | 178 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { |
178 int64_t position = _lseeki64(fd, 0, SEEK_END); | 179 int64_t position = _lseeki64(fd, 0, SEEK_END); |
179 if (position < 0) { | 180 if (position < 0) { |
180 return NULL; | 181 return NULL; |
(...skipping 13 matching lines...) Expand all Loading... |
194 break; | 195 break; |
195 default: | 196 default: |
196 UNREACHABLE(); | 197 UNREACHABLE(); |
197 } | 198 } |
198 return new File(new FileHandle(fd)); | 199 return new File(new FileHandle(fd)); |
199 } | 200 } |
200 | 201 |
201 | 202 |
202 bool File::Exists(const char* name) { | 203 bool File::Exists(const char* name) { |
203 struct __stat64 st; | 204 struct __stat64 st; |
204 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 205 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(name); |
205 bool stat_status = _wstat64(system_name, &st); | 206 bool stat_status = _wstat64(system_name, &st); |
206 free(const_cast<wchar_t*>(system_name)); | 207 free(const_cast<wchar_t*>(system_name)); |
207 if (stat_status == 0) { | 208 if (stat_status == 0) { |
208 return ((st.st_mode & S_IFMT) == S_IFREG); | 209 return ((st.st_mode & S_IFMT) == S_IFREG); |
209 } else { | 210 } else { |
210 return false; | 211 return false; |
211 } | 212 } |
212 } | 213 } |
213 | 214 |
214 | 215 |
215 bool File::Create(const char* name) { | 216 bool File::Create(const char* name) { |
216 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 217 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(name); |
217 int fd = _wopen(system_name, O_RDONLY | O_CREAT, 0666); | 218 int fd = _wopen(system_name, O_RDONLY | O_CREAT, 0666); |
218 free(const_cast<wchar_t*>(system_name)); | 219 free(const_cast<wchar_t*>(system_name)); |
219 if (fd < 0) { | 220 if (fd < 0) { |
220 return false; | 221 return false; |
221 } | 222 } |
222 return (close(fd) == 0); | 223 return (close(fd) == 0); |
223 } | 224 } |
224 | 225 |
225 | 226 |
226 // This structure is needed for creating and reading Junctions. | 227 // This structure is needed for creating and reading Junctions. |
(...skipping 25 matching lines...) Expand all Loading... |
252 } GenericReparseBuffer; | 253 } GenericReparseBuffer; |
253 }; | 254 }; |
254 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; | 255 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; |
255 | 256 |
256 | 257 |
257 static const int kReparseDataHeaderSize = sizeof ULONG + 2 * sizeof USHORT; | 258 static const int kReparseDataHeaderSize = sizeof ULONG + 2 * sizeof USHORT; |
258 static const int kMountPointHeaderSize = 4 * sizeof USHORT; | 259 static const int kMountPointHeaderSize = 4 * sizeof USHORT; |
259 | 260 |
260 | 261 |
261 bool File::CreateLink(const char* utf8_name, const char* utf8_target) { | 262 bool File::CreateLink(const char* utf8_name, const char* utf8_target) { |
262 const wchar_t* name = StringUtils::Utf8ToWide(utf8_name); | 263 const wchar_t* name = StringUtilsWin::Utf8ToWide(utf8_name); |
263 int create_status = CreateDirectoryW(name, NULL); | 264 int create_status = CreateDirectoryW(name, NULL); |
264 // If the directory already existed, treat it as a success. | 265 // If the directory already existed, treat it as a success. |
265 if (create_status == 0 && | 266 if (create_status == 0 && |
266 (GetLastError() != ERROR_ALREADY_EXISTS || | 267 (GetLastError() != ERROR_ALREADY_EXISTS || |
267 (GetFileAttributesW(name) & FILE_ATTRIBUTE_DIRECTORY) != 0)) { | 268 (GetFileAttributesW(name) & FILE_ATTRIBUTE_DIRECTORY) != 0)) { |
268 free(const_cast<wchar_t*>(name)); | 269 free(const_cast<wchar_t*>(name)); |
269 return false; | 270 return false; |
270 } | 271 } |
271 | 272 |
272 HANDLE dir_handle = CreateFileW( | 273 HANDLE dir_handle = CreateFileW( |
273 name, | 274 name, |
274 GENERIC_READ | GENERIC_WRITE, | 275 GENERIC_READ | GENERIC_WRITE, |
275 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 276 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
276 NULL, | 277 NULL, |
277 OPEN_EXISTING, | 278 OPEN_EXISTING, |
278 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, | 279 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, |
279 NULL); | 280 NULL); |
280 free(const_cast<wchar_t*>(name)); | 281 free(const_cast<wchar_t*>(name)); |
281 if (dir_handle == INVALID_HANDLE_VALUE) { | 282 if (dir_handle == INVALID_HANDLE_VALUE) { |
282 return false; | 283 return false; |
283 } | 284 } |
284 | 285 |
285 const wchar_t* target = StringUtils::Utf8ToWide(utf8_target); | 286 const wchar_t* target = StringUtilsWin::Utf8ToWide(utf8_target); |
286 int target_len = wcslen(target); | 287 int target_len = wcslen(target); |
287 if (target_len > MAX_PATH - 1) { | 288 if (target_len > MAX_PATH - 1) { |
288 free(const_cast<wchar_t*>(target)); | 289 free(const_cast<wchar_t*>(target)); |
289 CloseHandle(dir_handle); | 290 CloseHandle(dir_handle); |
290 return false; | 291 return false; |
291 } | 292 } |
292 | 293 |
293 int reparse_data_buffer_size = | 294 int reparse_data_buffer_size = |
294 sizeof REPARSE_DATA_BUFFER + 2 * MAX_PATH * sizeof WCHAR; | 295 sizeof REPARSE_DATA_BUFFER + 2 * MAX_PATH * sizeof WCHAR; |
295 REPARSE_DATA_BUFFER* reparse_data_buffer = | 296 REPARSE_DATA_BUFFER* reparse_data_buffer = |
(...skipping 23 matching lines...) Expand all Loading... |
319 &dummy_received_bytes, | 320 &dummy_received_bytes, |
320 NULL); | 321 NULL); |
321 if (CloseHandle(dir_handle) == 0) return false; | 322 if (CloseHandle(dir_handle) == 0) return false; |
322 free(const_cast<wchar_t*>(target)); | 323 free(const_cast<wchar_t*>(target)); |
323 free(reparse_data_buffer); | 324 free(reparse_data_buffer); |
324 return (result != 0); | 325 return (result != 0); |
325 } | 326 } |
326 | 327 |
327 | 328 |
328 bool File::Delete(const char* name) { | 329 bool File::Delete(const char* name) { |
329 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 330 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(name); |
330 int status = _wremove(system_name); | 331 int status = _wremove(system_name); |
331 free(const_cast<wchar_t*>(system_name)); | 332 free(const_cast<wchar_t*>(system_name)); |
332 return status != -1; | 333 return status != -1; |
333 } | 334 } |
334 | 335 |
335 | 336 |
336 bool File::DeleteLink(const char* name) { | 337 bool File::DeleteLink(const char* name) { |
337 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 338 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(name); |
338 bool result = false; | 339 bool result = false; |
339 DWORD attributes = GetFileAttributesW(system_name); | 340 DWORD attributes = GetFileAttributesW(system_name); |
340 if ((attributes != INVALID_FILE_ATTRIBUTES) && | 341 if ((attributes != INVALID_FILE_ATTRIBUTES) && |
341 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { | 342 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { |
342 // It's a junction(link), delete it. | 343 // It's a junction(link), delete it. |
343 result = (RemoveDirectoryW(system_name) != 0); | 344 result = (RemoveDirectoryW(system_name) != 0); |
344 } else { | 345 } else { |
345 SetLastError(ERROR_NOT_A_REPARSE_POINT); | 346 SetLastError(ERROR_NOT_A_REPARSE_POINT); |
346 } | 347 } |
347 free(const_cast<wchar_t*>(system_name)); | 348 free(const_cast<wchar_t*>(system_name)); |
348 return result; | 349 return result; |
349 } | 350 } |
350 | 351 |
351 | 352 |
352 bool File::Rename(const char* old_path, const char* new_path) { | 353 bool File::Rename(const char* old_path, const char* new_path) { |
353 File::Type type = GetType(old_path, false); | 354 File::Type type = GetType(old_path, false); |
354 if (type == kIsFile) { | 355 if (type == kIsFile) { |
355 const wchar_t* system_old_path = StringUtils::Utf8ToWide(old_path); | 356 const wchar_t* system_old_path = StringUtilsWin::Utf8ToWide(old_path); |
356 const wchar_t* system_new_path = StringUtils::Utf8ToWide(new_path); | 357 const wchar_t* system_new_path = StringUtilsWin::Utf8ToWide(new_path); |
357 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; | 358 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; |
358 int move_status = | 359 int move_status = |
359 MoveFileExW(system_old_path, system_new_path, flags); | 360 MoveFileExW(system_old_path, system_new_path, flags); |
360 free(const_cast<wchar_t*>(system_old_path)); | 361 free(const_cast<wchar_t*>(system_old_path)); |
361 free(const_cast<wchar_t*>(system_new_path)); | 362 free(const_cast<wchar_t*>(system_new_path)); |
362 return (move_status != 0); | 363 return (move_status != 0); |
363 } else { | 364 } else { |
364 SetLastError(ERROR_FILE_NOT_FOUND); | 365 SetLastError(ERROR_FILE_NOT_FOUND); |
365 } | 366 } |
366 return false; | 367 return false; |
367 } | 368 } |
368 | 369 |
369 | 370 |
370 bool File::RenameLink(const char* old_path, const char* new_path) { | 371 bool File::RenameLink(const char* old_path, const char* new_path) { |
371 File::Type type = GetType(old_path, false); | 372 File::Type type = GetType(old_path, false); |
372 if (type == kIsLink) { | 373 if (type == kIsLink) { |
373 const wchar_t* system_old_path = StringUtils::Utf8ToWide(old_path); | 374 const wchar_t* system_old_path = StringUtilsWin::Utf8ToWide(old_path); |
374 const wchar_t* system_new_path = StringUtils::Utf8ToWide(new_path); | 375 const wchar_t* system_new_path = StringUtilsWin::Utf8ToWide(new_path); |
375 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; | 376 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; |
376 int move_status = | 377 int move_status = |
377 MoveFileExW(system_old_path, system_new_path, flags); | 378 MoveFileExW(system_old_path, system_new_path, flags); |
378 free(const_cast<wchar_t*>(system_old_path)); | 379 free(const_cast<wchar_t*>(system_old_path)); |
379 free(const_cast<wchar_t*>(system_new_path)); | 380 free(const_cast<wchar_t*>(system_new_path)); |
380 return (move_status != 0); | 381 return (move_status != 0); |
381 } else { | 382 } else { |
382 SetLastError(ERROR_FILE_NOT_FOUND); | 383 SetLastError(ERROR_FILE_NOT_FOUND); |
383 } | 384 } |
384 return false; | 385 return false; |
385 } | 386 } |
386 | 387 |
387 | 388 |
388 bool File::Copy(const char* old_path, const char* new_path) { | 389 bool File::Copy(const char* old_path, const char* new_path) { |
389 File::Type type = GetType(old_path, false); | 390 File::Type type = GetType(old_path, false); |
390 if (type == kIsFile) { | 391 if (type == kIsFile) { |
391 const wchar_t* system_old_path = StringUtils::Utf8ToWide(old_path); | 392 const wchar_t* system_old_path = StringUtilsWin::Utf8ToWide(old_path); |
392 const wchar_t* system_new_path = StringUtils::Utf8ToWide(new_path); | 393 const wchar_t* system_new_path = StringUtilsWin::Utf8ToWide(new_path); |
393 bool success = CopyFileExW(system_old_path, | 394 bool success = CopyFileExW(system_old_path, |
394 system_new_path, | 395 system_new_path, |
395 NULL, | 396 NULL, |
396 NULL, | 397 NULL, |
397 NULL, | 398 NULL, |
398 0) != 0; | 399 0) != 0; |
399 free(const_cast<wchar_t*>(system_old_path)); | 400 free(const_cast<wchar_t*>(system_old_path)); |
400 free(const_cast<wchar_t*>(system_new_path)); | 401 free(const_cast<wchar_t*>(system_new_path)); |
401 return success; | 402 return success; |
402 } else { | 403 } else { |
403 SetLastError(ERROR_FILE_NOT_FOUND); | 404 SetLastError(ERROR_FILE_NOT_FOUND); |
404 } | 405 } |
405 return false; | 406 return false; |
406 } | 407 } |
407 | 408 |
408 | 409 |
409 int64_t File::LengthFromPath(const char* name) { | 410 int64_t File::LengthFromPath(const char* name) { |
410 struct __stat64 st; | 411 struct __stat64 st; |
411 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 412 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(name); |
412 int stat_status = _wstat64(system_name, &st); | 413 int stat_status = _wstat64(system_name, &st); |
413 free(const_cast<wchar_t*>(system_name)); | 414 free(const_cast<wchar_t*>(system_name)); |
414 if (stat_status == 0) { | 415 if (stat_status == 0) { |
415 return st.st_size; | 416 return st.st_size; |
416 } | 417 } |
417 return -1; | 418 return -1; |
418 } | 419 } |
419 | 420 |
420 | 421 |
421 char* File::LinkTarget(const char* pathname) { | 422 char* File::LinkTarget(const char* pathname) { |
422 const wchar_t* name = StringUtils::Utf8ToWide(pathname); | 423 const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); |
423 HANDLE dir_handle = CreateFileW( | 424 HANDLE dir_handle = CreateFileW( |
424 name, | 425 name, |
425 GENERIC_READ, | 426 GENERIC_READ, |
426 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 427 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
427 NULL, | 428 NULL, |
428 OPEN_EXISTING, | 429 OPEN_EXISTING, |
429 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, | 430 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, |
430 NULL); | 431 NULL); |
431 free(const_cast<wchar_t*>(name)); | 432 free(const_cast<wchar_t*>(name)); |
432 if (dir_handle == INVALID_HANDLE_VALUE) { | 433 if (dir_handle == INVALID_HANDLE_VALUE) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 free(buffer); | 510 free(buffer); |
510 return utf8_target; | 511 return utf8_target; |
511 } | 512 } |
512 | 513 |
513 | 514 |
514 void File::Stat(const char* name, int64_t* data) { | 515 void File::Stat(const char* name, int64_t* data) { |
515 File::Type type = GetType(name, false); | 516 File::Type type = GetType(name, false); |
516 data[kType] = type; | 517 data[kType] = type; |
517 if (type != kDoesNotExist) { | 518 if (type != kDoesNotExist) { |
518 struct _stat64 st; | 519 struct _stat64 st; |
519 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 520 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(name); |
520 int stat_status = _wstat64(system_name, &st); | 521 int stat_status = _wstat64(system_name, &st); |
521 free(const_cast<wchar_t*>(system_name)); | 522 free(const_cast<wchar_t*>(system_name)); |
522 if (stat_status == 0) { | 523 if (stat_status == 0) { |
523 data[kCreatedTime] = st.st_ctime * 1000; | 524 data[kCreatedTime] = st.st_ctime * 1000; |
524 data[kModifiedTime] = st.st_mtime * 1000; | 525 data[kModifiedTime] = st.st_mtime * 1000; |
525 data[kAccessedTime] = st.st_atime * 1000; | 526 data[kAccessedTime] = st.st_atime * 1000; |
526 data[kMode] = st.st_mode; | 527 data[kMode] = st.st_mode; |
527 data[kSize] = st.st_size; | 528 data[kSize] = st.st_size; |
528 } else { | 529 } else { |
529 data[kType] = File::kDoesNotExist; | 530 data[kType] = File::kDoesNotExist; |
530 } | 531 } |
531 } | 532 } |
532 } | 533 } |
533 | 534 |
534 | 535 |
535 time_t File::LastModified(const char* name) { | 536 time_t File::LastModified(const char* name) { |
536 struct __stat64 st; | 537 struct __stat64 st; |
537 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 538 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(name); |
538 int stat_status = _wstat64(system_name, &st); | 539 int stat_status = _wstat64(system_name, &st); |
539 free(const_cast<wchar_t*>(system_name)); | 540 free(const_cast<wchar_t*>(system_name)); |
540 if (stat_status == 0) { | 541 if (stat_status == 0) { |
541 return st.st_mtime; | 542 return st.st_mtime; |
542 } | 543 } |
543 return -1; | 544 return -1; |
544 } | 545 } |
545 | 546 |
546 | 547 |
547 bool File::IsAbsolutePath(const char* pathname) { | 548 bool File::IsAbsolutePath(const char* pathname) { |
548 // Should we consider network paths? | 549 // Should we consider network paths? |
549 if (pathname == NULL) return false; | 550 if (pathname == NULL) return false; |
550 return (strlen(pathname) > 2) && | 551 return (strlen(pathname) > 2) && |
551 (pathname[1] == ':') && | 552 (pathname[1] == ':') && |
552 (pathname[2] == '\\' || pathname[2] == '/'); | 553 (pathname[2] == '\\' || pathname[2] == '/'); |
553 } | 554 } |
554 | 555 |
555 | 556 |
556 char* File::GetCanonicalPath(const char* pathname) { | 557 char* File::GetCanonicalPath(const char* pathname) { |
557 const wchar_t* system_name = StringUtils::Utf8ToWide(pathname); | 558 const wchar_t* system_name = StringUtilsWin::Utf8ToWide(pathname); |
558 HANDLE file_handle = CreateFileW( | 559 HANDLE file_handle = CreateFileW( |
559 system_name, | 560 system_name, |
560 0, | 561 0, |
561 FILE_SHARE_READ, | 562 FILE_SHARE_READ, |
562 NULL, | 563 NULL, |
563 OPEN_EXISTING, | 564 OPEN_EXISTING, |
564 FILE_FLAG_BACKUP_SEMANTICS, | 565 FILE_FLAG_BACKUP_SEMANTICS, |
565 NULL); | 566 NULL); |
566 if (file_handle == INVALID_HANDLE_VALUE) { | 567 if (file_handle == INVALID_HANDLE_VALUE) { |
567 free(const_cast<wchar_t*>(system_name)); | 568 free(const_cast<wchar_t*>(system_name)); |
(...skipping 17 matching lines...) Expand all Loading... |
585 path, | 586 path, |
586 required_size, | 587 required_size, |
587 VOLUME_NAME_DOS); | 588 VOLUME_NAME_DOS); |
588 ASSERT(result_size <= required_size - 1); | 589 ASSERT(result_size <= required_size - 1); |
589 // Remove leading \\?\ if possible, unless input used it. | 590 // Remove leading \\?\ if possible, unless input used it. |
590 char* result; | 591 char* result; |
591 if (result_size < MAX_PATH - 1 + 4 && | 592 if (result_size < MAX_PATH - 1 + 4 && |
592 result_size > 4 && | 593 result_size > 4 && |
593 wcsncmp(path, L"\\\\?\\", 4) == 0 && | 594 wcsncmp(path, L"\\\\?\\", 4) == 0 && |
594 wcsncmp(system_name, L"\\\\?\\", 4) != 0) { | 595 wcsncmp(system_name, L"\\\\?\\", 4) != 0) { |
595 result = StringUtils::WideToUtf8(path + 4); | 596 result = StringUtilsWin::WideToUtf8(path + 4); |
596 } else { | 597 } else { |
597 result = StringUtils::WideToUtf8(path); | 598 result = StringUtilsWin::WideToUtf8(path); |
598 } | 599 } |
599 free(const_cast<wchar_t*>(system_name)); | 600 free(const_cast<wchar_t*>(system_name)); |
600 free(path); | 601 free(path); |
601 CloseHandle(file_handle); | 602 CloseHandle(file_handle); |
602 return result; | 603 return result; |
603 } | 604 } |
604 | 605 |
605 | 606 |
606 const char* File::PathSeparator() { | 607 const char* File::PathSeparator() { |
607 // This is already UTF-8 encoded. | 608 // This is already UTF-8 encoded. |
608 return "\\"; | 609 return "\\"; |
609 } | 610 } |
610 | 611 |
611 | 612 |
612 const char* File::StringEscapedPathSeparator() { | 613 const char* File::StringEscapedPathSeparator() { |
613 // This is already UTF-8 encoded. | 614 // This is already UTF-8 encoded. |
614 return "\\\\"; | 615 return "\\\\"; |
615 } | 616 } |
616 | 617 |
617 | 618 |
618 File::StdioHandleType File::GetStdioHandleType(int fd) { | 619 File::StdioHandleType File::GetStdioHandleType(int fd) { |
619 // Treat all stdio handles as pipes. The Windows event handler and | 620 // Treat all stdio handles as pipes. The Windows event handler and |
620 // socket code will handle the different handle types. | 621 // socket code will handle the different handle types. |
621 return kPipe; | 622 return kPipe; |
622 } | 623 } |
623 | 624 |
624 | 625 |
625 File::Type File::GetType(const char* pathname, bool follow_links) { | 626 File::Type File::GetType(const char* pathname, bool follow_links) { |
626 const wchar_t* name = StringUtils::Utf8ToWide(pathname); | 627 const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); |
627 DWORD attributes = GetFileAttributesW(name); | 628 DWORD attributes = GetFileAttributesW(name); |
628 File::Type result = kIsFile; | 629 File::Type result = kIsFile; |
629 if (attributes == INVALID_FILE_ATTRIBUTES) { | 630 if (attributes == INVALID_FILE_ATTRIBUTES) { |
630 result = kDoesNotExist; | 631 result = kDoesNotExist; |
631 } else if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { | 632 } else if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { |
632 if (follow_links) { | 633 if (follow_links) { |
633 HANDLE dir_handle = CreateFileW( | 634 HANDLE dir_handle = CreateFileW( |
634 name, | 635 name, |
635 0, | 636 0, |
636 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 637 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
(...skipping 15 matching lines...) Expand all Loading... |
652 } | 653 } |
653 free(const_cast<wchar_t*>(name)); | 654 free(const_cast<wchar_t*>(name)); |
654 return result; | 655 return result; |
655 } | 656 } |
656 | 657 |
657 | 658 |
658 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { | 659 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
659 BY_HANDLE_FILE_INFORMATION file_info[2]; | 660 BY_HANDLE_FILE_INFORMATION file_info[2]; |
660 const char* file_names[2] = { file_1, file_2 }; | 661 const char* file_names[2] = { file_1, file_2 }; |
661 for (int i = 0; i < 2; ++i) { | 662 for (int i = 0; i < 2; ++i) { |
662 const wchar_t* wide_name = StringUtils::Utf8ToWide(file_names[i]); | 663 const wchar_t* wide_name = StringUtilsWin::Utf8ToWide(file_names[i]); |
663 HANDLE file_handle = CreateFileW( | 664 HANDLE file_handle = CreateFileW( |
664 wide_name, | 665 wide_name, |
665 0, | 666 0, |
666 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 667 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
667 NULL, | 668 NULL, |
668 OPEN_EXISTING, | 669 OPEN_EXISTING, |
669 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, | 670 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, |
670 NULL); | 671 NULL); |
671 if (file_handle == INVALID_HANDLE_VALUE) { | 672 if (file_handle == INVALID_HANDLE_VALUE) { |
672 free(const_cast<wchar_t*>(wide_name)); | 673 free(const_cast<wchar_t*>(wide_name)); |
(...skipping 17 matching lines...) Expand all Loading... |
690 return kIdentical; | 691 return kIdentical; |
691 } else { | 692 } else { |
692 return kDifferent; | 693 return kDifferent; |
693 } | 694 } |
694 } | 695 } |
695 | 696 |
696 } // namespace bin | 697 } // namespace bin |
697 } // namespace dart | 698 } // namespace dart |
698 | 699 |
699 #endif // defined(TARGET_OS_WINDOWS) | 700 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |