Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1453)

Side by Side Diff: runtime/bin/file_win.cc

Issue 12812010: dart:io | Add Link.targetSync on all platforms. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Windows failures. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 const wchar_t* system_name = StringUtils::Utf8ToWide(name); 272 const wchar_t* system_name = StringUtils::Utf8ToWide(name);
273 int stat_status = _wstat(system_name, &st); 273 int stat_status = _wstat(system_name, &st);
274 free(const_cast<wchar_t*>(system_name)); 274 free(const_cast<wchar_t*>(system_name));
275 if (stat_status == 0) { 275 if (stat_status == 0) {
276 return st.st_size; 276 return st.st_size;
277 } 277 }
278 return -1; 278 return -1;
279 } 279 }
280 280
281 281
282 char* File::LinkTarget(const char* pathname) {
283 const wchar_t* name = StringUtils::Utf8ToWide(pathname);
284 HANDLE dir_handle = CreateFileW(
285 name,
286 GENERIC_READ,
287 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
288 NULL,
289 OPEN_EXISTING,
290 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
291 NULL);
292 free(const_cast<wchar_t*>(name));
293 if (dir_handle == INVALID_HANDLE_VALUE) {
294 return NULL;
295 }
296
297 int reparse_data_buffer_size =
298 sizeof REPARSE_DATA_BUFFER + 2 * (MAX_PATH + 1) * sizeof WCHAR;
299 REPARSE_DATA_BUFFER* reparse_data_buffer =
300 static_cast<REPARSE_DATA_BUFFER*>(calloc(reparse_data_buffer_size, 1));
301 DWORD received_bytes;
302 int result = DeviceIoControl(
303 dir_handle,
304 FSCTL_GET_REPARSE_POINT,
305 NULL,
306 0,
307 reparse_data_buffer,
308 reparse_data_buffer_size,
309 &received_bytes,
310 NULL);
311 if (CloseHandle(dir_handle) == 0) return NULL;
312 if (result == 0) return NULL;
313 if (reparse_data_buffer->ReparseTag != IO_REPARSE_TAG_MOUNT_POINT) {
314 return NULL;
315 }
316 wchar_t* target = reparse_data_buffer->MountPointReparseBuffer.PathBuffer +
317 reparse_data_buffer->MountPointReparseBuffer.SubstituteNameOffset;
318 size_t target_length =
319 reparse_data_buffer->MountPointReparseBuffer.SubstituteNameLength;
320 if (wcsncmp(L"\\??\\", target, 4) != 0) return NULL;
321 target += 4;
Bill Hesse 2013/03/18 09:05:54 We really need to copy the data out here, because
322 char* target_string = StringUtils::WideToUtf8(target);
323 free(reparse_data_buffer);
324 return target_string;
325 }
326
327
282 time_t File::LastModified(const char* name) { 328 time_t File::LastModified(const char* name) {
283 struct _stat st; 329 struct _stat st;
284 const wchar_t* system_name = StringUtils::Utf8ToWide(name); 330 const wchar_t* system_name = StringUtils::Utf8ToWide(name);
285 int stat_status = _wstat(system_name, &st); 331 int stat_status = _wstat(system_name, &st);
286 free(const_cast<wchar_t*>(system_name)); 332 free(const_cast<wchar_t*>(system_name));
287 if (stat_status == 0) { 333 if (stat_status == 0) {
288 return st.st_mtime; 334 return st.st_mtime;
289 } 335 }
290 return -1; 336 return -1;
291 } 337 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 456 }
411 } 457 }
412 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { 458 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
413 return File::kIsDirectory; 459 return File::kIsDirectory;
414 } else { 460 } else {
415 return File::kIsFile; 461 return File::kIsFile;
416 } 462 }
417 } 463 }
418 464
419 #endif // defined(TARGET_OS_WINDOWS) 465 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698