@@ -173,36 +173,41 @@ Result<DWORD> GetFileAttributes(const std::wstring& filename) {
173
173
#endif
174
174
175
175
void UnlockWin32Lock (FileDescriptor fd) {
176
+ TS_DETAIL_LOG_BEGIN << " handle=" << fd;
176
177
auto lock_offset = GetLockOverlapped ();
177
178
// Ignore any errors.
178
179
::UnlockFileEx (fd, /* dwReserved=*/ 0 , /* nNumberOfBytesToUnlockLow=*/ 1 ,
179
180
/* nNumberOfBytesToUnlockHigh=*/ 0 ,
180
181
/* lpOverlapped=*/ &lock_offset);
182
+ TS_DETAIL_LOG_END << " handle=" << fd;
181
183
}
182
184
183
185
} // namespace
184
186
185
- void FileDescriptorTraits::Close (FileDescriptor handle ) {
186
- TS_DETAIL_LOG_BEGIN << " handle=" << handle ;
187
- ::CloseHandle (handle );
188
- TS_DETAIL_LOG_END << " handle=" << handle ;
187
+ void FileDescriptorTraits::Close (FileDescriptor fd ) {
188
+ TS_DETAIL_LOG_BEGIN << " handle=" << fd ;
189
+ ::CloseHandle (fd );
190
+ TS_DETAIL_LOG_END << " handle=" << fd ;
189
191
}
190
192
191
193
Result<UnlockFn> AcquireFdLock (FileDescriptor fd) {
194
+ TS_DETAIL_LOG_BEGIN << " handle=" << fd;
192
195
auto lock_offset = GetLockOverlapped ();
193
196
if (::LockFileEx (fd, /* dwFlags=*/ LOCKFILE_EXCLUSIVE_LOCK,
194
197
/* dwReserved=*/ 0 ,
195
198
/* nNumberOfBytesToLockLow=*/ 1 ,
196
199
/* nNumberOfBytesToLockHigh=*/ 0 ,
197
200
/* lpOverlapped=*/ &lock_offset)) {
201
+ TS_DETAIL_LOG_END << " handle=" << fd;
198
202
return UnlockWin32Lock;
199
203
}
204
+ TS_DETAIL_LOG_ERROR << " handle=" << fd;
200
205
return StatusFromOsError (::GetLastError (), " Failed to lock file" );
201
206
}
202
207
203
208
Result<UniqueFileDescriptor> OpenExistingFileForReading (
204
209
const std::string& path) {
205
- TS_DETAIL_LOG_BEGIN << " path=" << tensorstore:: QuoteString (path);
210
+ TS_DETAIL_LOG_BEGIN << " path=" << QuoteString (path);
206
211
std::wstring wpath;
207
212
TENSORSTORE_RETURN_IF_ERROR (ConvertUTF8ToWindowsWide (path, wpath));
208
213
@@ -215,17 +220,16 @@ Result<UniqueFileDescriptor> OpenExistingFileForReading(
215
220
/* hTemplateFile=*/ nullptr );
216
221
217
222
if (fd == FileDescriptorTraits::Invalid ()) {
218
- TS_DETAIL_LOG_ERROR << " path=" << tensorstore:: QuoteString (path);
223
+ TS_DETAIL_LOG_ERROR << " path=" << QuoteString (path);
219
224
return StatusFromOsError (::GetLastError (),
220
225
" Failed to open: " , QuoteString (path));
221
226
}
222
- TS_DETAIL_LOG_END << " path=" << tensorstore::QuoteString (path)
223
- << " , handle=" << fd;
227
+ TS_DETAIL_LOG_END << " path=" << QuoteString (path) << " , handle=" << fd;
224
228
return UniqueFileDescriptor (fd);
225
229
}
226
230
227
231
Result<UniqueFileDescriptor> OpenFileForWriting (const std::string& path) {
228
- TS_DETAIL_LOG_BEGIN << " path=" << tensorstore:: QuoteString (path);
232
+ TS_DETAIL_LOG_BEGIN << " path=" << QuoteString (path);
229
233
std::wstring wpath;
230
234
TENSORSTORE_RETURN_IF_ERROR (ConvertUTF8ToWindowsWide (path, wpath));
231
235
@@ -242,12 +246,11 @@ Result<UniqueFileDescriptor> OpenFileForWriting(const std::string& path) {
242
246
/* hTemplateFile=*/ nullptr );
243
247
244
248
if (fd == FileDescriptorTraits::Invalid ()) {
245
- TS_DETAIL_LOG_ERROR << " path=" << tensorstore:: QuoteString (path);
249
+ TS_DETAIL_LOG_ERROR << " path=" << QuoteString (path);
246
250
return StatusFromOsError (::GetLastError (),
247
251
" Failed to create: " , QuoteString (path));
248
252
}
249
- TS_DETAIL_LOG_END << " path=" << tensorstore::QuoteString (path)
250
- << " , handle=" << fd;
253
+ TS_DETAIL_LOG_END << " path=" << QuoteString (path) << " , handle=" << fd;
251
254
return UniqueFileDescriptor (fd);
252
255
}
253
256
@@ -310,11 +313,15 @@ absl::Status TruncateFile(FileDescriptor fd) {
310
313
311
314
absl::Status RenameOpenFile (FileDescriptor fd, const std::string& old_name,
312
315
const std::string& new_name) {
316
+ TS_DETAIL_LOG_BEGIN << " handle=" << fd
317
+ << " , old_name=" << QuoteString (old_name)
318
+ << " , new_name=" << QuoteString (new_name);
313
319
std::wstring wpath_new;
314
320
TENSORSTORE_RETURN_IF_ERROR (ConvertUTF8ToWindowsWide (new_name, wpath_new));
315
321
316
322
// Try using Posix semantics.
317
323
if (RenameFilePosix (fd, wpath_new)) {
324
+ TS_DETAIL_LOG_END << " handle=" << fd;
318
325
return absl::OkStatus ();
319
326
}
320
327
@@ -330,9 +337,11 @@ absl::Status RenameOpenFile(FileDescriptor fd, const std::string& old_name,
330
337
// Try using MoveFileEx, which may not be atomic.
331
338
if (::MoveFileExW(wpath_old.c_str(), wpath_new.c_str(),
332
339
MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) {
340
+ TS_DETAIL_LOG_END << " handle=" << fd;
333
341
return absl::OkStatus();
334
342
}
335
343
344
+ TS_DETAIL_LOG_ERROR << " handle=" << fd;
336
345
return StatusFromOsError(::GetLastError(),
337
346
" Failed to rename: " , QuoteString(old_name),
338
347
" to: " , QuoteString(new_name));
@@ -347,6 +356,7 @@ absl::Status DeleteOpenFile(FileDescriptor fd, const std::string& path) {
347
356
// result in the normal read/write paths failing with an error. To avoid
348
357
// that problem, we first rename the file to a random name, with a suffix of
349
358
// `kLockSuffix` to prevent it from being included in List results.
359
+ TS_DETAIL_LOG_BEGIN << " handle=" << fd << " , path=" << QuoteString(path);
350
360
unsigned int buf[5];
351
361
for (int i = 0; i < 5; ++i) {
352
362
::rand_s(&buf[i]);
@@ -374,6 +384,7 @@ absl::Status DeleteOpenFile(FileDescriptor fd, const std::string& path) {
374
384
}
375
385
// Attempt to delete the open handle using posix semantics?
376
386
if (DeleteFilePosix(fd)) {
387
+ TS_DETAIL_LOG_END << " handle=" << fd;
377
388
return absl::OkStatus();
378
389
}
379
390
#ifndef NDEBUG
@@ -383,8 +394,10 @@ absl::Status DeleteOpenFile(FileDescriptor fd, const std::string& path) {
383
394
#endif
384
395
// The file has been renamed, so delete the renamed file.
385
396
if (::DeleteFileW(wpath_temp.c_str())) {
397
+ TS_DETAIL_LOG_END << " handle=" << fd;
386
398
return absl::OkStatus();
387
399
}
400
+ TS_DETAIL_LOG_ERROR << " handle=" << fd;
388
401
return StatusFromOsError(::GetLastError(),
389
402
" Failed to delete : " , QuoteString(path));
390
403
}
@@ -431,7 +444,7 @@ absl::Status GetFileInfo(FileDescriptor fd, FileInfo* info) {
431
444
}
432
445
433
446
absl::Status GetFileInfo(const std::string& path, FileInfo* info) {
434
- TS_DETAIL_LOG_BEGIN << " path=" << tensorstore:: QuoteString(path);
447
+ TS_DETAIL_LOG_BEGIN << " path=" << QuoteString(path);
435
448
436
449
// The typedef uses BY_HANDLE_FILE_INFO, which includes device and index
437
450
// metadata, and requires an open handle.
@@ -446,11 +459,11 @@ absl::Status GetFileInfo(const std::string& path, FileInfo* info) {
446
459
/*hTemplateFile=*/nullptr));
447
460
if (stat_fd.valid()) {
448
461
if (::GetFileInformationByHandle(stat_fd.get(), info)) {
449
- TS_DETAIL_LOG_END << " path=" << tensorstore:: QuoteString(path);
462
+ TS_DETAIL_LOG_END << " path=" << QuoteString(path);
450
463
return absl::OkStatus();
451
464
}
452
465
}
453
- TS_DETAIL_LOG_ERROR << " path=" << tensorstore:: QuoteString(path);
466
+ TS_DETAIL_LOG_ERROR << " path=" << QuoteString(path);
454
467
return StatusFromOsError(::GetLastError());
455
468
}
456
469
0 commit comments