188
188
RTR3DECL(int) RTPathQueryInfo(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
190
return RTPathQueryInfoEx(pszPath, pObjInfo, enmAdditionalAttribs, RTPATH_F_ON_LINK);
194
RTR3DECL(int) RTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags)
191
197
* Validate input.
195
AssertMsgFailed(("Invalid pszPath=%p\n", pszPath));
196
return VERR_INVALID_PARAMETER;
200
AssertMsgFailed(("Invalid pObjInfo=%p\n", pObjInfo));
201
return VERR_INVALID_PARAMETER;
203
if ( enmAdditionalAttribs < RTFSOBJATTRADD_NOTHING
204
|| enmAdditionalAttribs > RTFSOBJATTRADD_LAST)
206
AssertMsgFailed(("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs));
207
return VERR_INVALID_PARAMETER;
199
AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
200
AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
201
AssertPtrReturn(pObjInfo, VERR_INVALID_POINTER);
202
AssertMsgReturn( enmAdditionalAttribs >= RTFSOBJATTRADD_NOTHING
203
&& enmAdditionalAttribs <= RTFSOBJATTRADD_LAST,
204
("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs),
205
VERR_INVALID_PARAMETER);
206
AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
211
209
* Query file info.
219
217
if (!GetFileAttributesExW(pwszPath, GetFileExInfoStandard, &Data))
221
rc = RTErrConvertFromWin32(GetLastError());
222
RTUtf16Free(pwszPath);
219
/* Fallback to FindFileFirst in case of sharing violation. */
220
if (GetLastError() == ERROR_SHARING_VIOLATION)
222
WIN32_FIND_DATAW FindData;
223
HANDLE hDir = FindFirstFileW(pwszPath, &FindData);
224
if (hDir == INVALID_HANDLE_VALUE)
226
rc = RTErrConvertFromWin32(GetLastError());
227
RTUtf16Free(pwszPath);
231
Data.dwFileAttributes = FindData.dwFileAttributes;
232
Data.ftCreationTime = FindData.ftCreationTime;
233
Data.ftLastAccessTime = FindData.ftLastAccessTime;
234
Data.ftLastWriteTime = FindData.ftLastWriteTime;
235
Data.nFileSizeHigh = FindData.nFileSizeHigh;
236
Data.nFileSizeLow = FindData.nFileSizeLow;
240
rc = RTErrConvertFromWin32(GetLastError());
241
RTUtf16Free(pwszPath);
225
245
RTUtf16Free(pwszPath);
227
247
if (!GetFileAttributesExA(pszPath, GetFileExInfoStandard, &Data))
228
return RTErrConvertFromWin32(GetLastError());
249
/* Fallback to FindFileFirst in case of sharing violation. */
250
if (GetLastError() != ERROR_SHARING_VIOLATION)
251
return RTErrConvertFromWin32(GetLastError());
252
WIN32_FIND_DATAA FindData;
253
HANDLE hDir = FindFirstFileA(pszPath, &FindData);
254
if (hDir == INVALID_HANDLE_VALUE)
255
return RTErrConvertFromWin32(GetLastError());
257
Data.dwFileAttributes = FindData.dwFileAttributes;
258
Data.ftCreationTime = FindData.ftCreationTime;
259
Data.ftLastAccessTime = FindData.ftLastAccessTime;
260
Data.ftLastWriteTime = FindData.ftLastWriteTime;
261
Data.nFileSizeHigh = FindData.nFileSizeHigh;
262
Data.nFileSizeLow = FindData.nFileSizeLow;
265
if ( (fFlags & RTPATH_F_FOLLOW_LINK)
266
&& (Data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))
268
#ifndef DEBUG_sandervl
271
/** @todo Symlinks: RTPathQueryInfoEx is not handling symbolic links
272
* correctly on Windows. (Both GetFileAttributesEx and FileFindFirst
273
* will return info about the symlink.) */
232
277
* Setup the returned data.
282
327
RTR3DECL(int) RTPathSetTimes(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
283
328
PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
330
return RTPathSetTimesEx(pszPath, pAccessTime, pModificationTime, pChangeTime, pBirthTime, RTPATH_F_ON_LINK);
334
RTR3DECL(int) RTPathSetTimesEx(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
335
PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags)
286
338
* Validate input.
288
AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER);
289
AssertMsgReturn(*pszPath, ("%p\n", pszPath), VERR_INVALID_PARAMETER);
290
AssertMsgReturn(!pAccessTime || VALID_PTR(pAccessTime), ("%p\n", pAccessTime), VERR_INVALID_POINTER);
291
AssertMsgReturn(!pModificationTime || VALID_PTR(pModificationTime), ("%p\n", pModificationTime), VERR_INVALID_POINTER);
292
AssertMsgReturn(!pChangeTime || VALID_PTR(pChangeTime), ("%p\n", pChangeTime), VERR_INVALID_POINTER);
293
AssertMsgReturn(!pBirthTime || VALID_PTR(pBirthTime), ("%p\n", pBirthTime), VERR_INVALID_POINTER);
340
AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
341
AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
342
AssertPtrNullReturn(pAccessTime, VERR_INVALID_POINTER);
343
AssertPtrNullReturn(pModificationTime, VERR_INVALID_POINTER);
344
AssertPtrNullReturn(pChangeTime, VERR_INVALID_POINTER);
345
AssertPtrNullReturn(pBirthTime, VERR_INVALID_POINTER);
346
AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
296
349
* Convert the path.
299
352
int rc = RTStrToUtf16(pszPath, &pwszPath);
300
353
if (RT_SUCCESS(rc))
302
HANDLE hFile = CreateFileW(pwszPath,
303
FILE_WRITE_ATTRIBUTES, /* dwDesiredAccess */
304
FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, /* dwShareMode */
305
NULL, /* security attribs */
306
OPEN_EXISTING, /* dwCreationDisposition */
307
FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL,
356
if (fFlags & RTPATH_F_FOLLOW_LINK)
357
hFile = CreateFileW(pwszPath,
358
FILE_WRITE_ATTRIBUTES, /* dwDesiredAccess */
359
FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, /* dwShareMode */
360
NULL, /* security attribs */
361
OPEN_EXISTING, /* dwCreationDisposition */
362
FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL,
366
/** @todo Symlink: Test RTPathSetTimesEx on Windows. (The code is disabled
367
* because it's not tested yet.) */
368
#if 0 //def FILE_FLAG_OPEN_REPARSE_POINT
369
hFile = CreateFileW(pwszPath,
370
FILE_WRITE_ATTRIBUTES, /* dwDesiredAccess */
371
FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, /* dwShareMode */
372
NULL, /* security attribs */
373
OPEN_EXISTING, /* dwCreationDisposition */
374
FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OPEN_REPARSE_POINT,
377
if (hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_INVALID_PARAMETER)
379
hFile = CreateFileW(pwszPath,
380
FILE_WRITE_ATTRIBUTES, /* dwDesiredAccess */
381
FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, /* dwShareMode */
382
NULL, /* security attribs */
383
OPEN_EXISTING, /* dwCreationDisposition */
384
FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL,
309
387
if (hFile != INVALID_HANDLE_VALUE)
448
* Checks if the path exists.
450
* Symbolic links will all be attempted resolved.
452
* @returns true if it exists and false if it doesn't
453
* @param pszPath The path to check.
455
525
RTDECL(bool) RTPathExists(const char *pszPath)
527
return RTPathExistsEx(pszPath, RTPATH_F_FOLLOW_LINK);
531
RTDECL(bool) RTPathExistsEx(const char *pszPath, uint32_t fFlags)
458
534
* Validate input.
460
536
AssertPtrReturn(pszPath, false);
461
537
AssertReturn(*pszPath, false);
538
Assert(RTPATH_F_IS_VALID(fFlags, 0));
464
541
* Try query file info.
466
544
#ifndef RT_DONT_CONVERT_FILENAMES
467
545
PRTUTF16 pwszPath;
468
546
int rc = RTStrToUtf16(pszPath, &pwszPath);
469
547
if (RT_SUCCESS(rc))
471
if (GetFileAttributesW(pwszPath) == INVALID_FILE_ATTRIBUTES)
472
rc = VERR_GENERAL_FAILURE;
549
dwAttr = GetFileAttributesW(pwszPath);
473
550
RTUtf16Free(pwszPath);
553
dwAttr = INVALID_FILE_ATTRIBUTES;
476
int rc = VINF_SUCCESS;
477
if (GetFileAttributesExA(pszPath) == INVALID_FILE_ATTRIBUTES)
478
rc = VERR_GENERAL_FAILURE;
481
return RT_SUCCESS(rc);
555
dwAttr = GetFileAttributesA(pszPath);
558
if (dwAttr == INVALID_FILE_ATTRIBUTES)
561
#ifdef FILE_ATTRIBUTE_REPARSE_POINT
562
if ( (fFlags & RTPATH_F_FOLLOW_LINK)
563
&& (dwAttr & FILE_ATTRIBUTE_REPARSE_POINT))
566
/** @todo Symlinks: RTPathExists+RTPathExistsEx is misbehaving on symbolic
567
* links on Windows. */