OSDN Git Service

* path.cc (symlink_info::check): In case of ERROR_SHARING_VIOLATION and
authorcorinna <corinna>
Tue, 14 Aug 2007 16:19:13 +0000 (16:19 +0000)
committercorinna <corinna>
Tue, 14 Aug 2007 16:19:13 +0000 (16:19 +0000)
ERROR_ACCESS_DENIED, try to get file attributes by using directory
functions.

winsup/cygwin/ChangeLog
winsup/cygwin/path.cc

index 54ae41a..51f338e 100644 (file)
@@ -1,5 +1,11 @@
 2007-08-14  Corinna Vinschen  <corinna@vinschen.de>
 
+       * path.cc (symlink_info::check): In case of ERROR_SHARING_VIOLATION and
+       ERROR_ACCESS_DENIED, try to get file attributes by using directory
+       functions.
+
+2007-08-14  Corinna Vinschen  <corinna@vinschen.de>
+
        * path.cc (fs_info::update): Correctly handle the volume root directory.
 
 2007-08-14  Corinna Vinschen  <corinna@vinschen.de>
index 88747db..b616a10 100644 (file)
@@ -3518,16 +3518,29 @@ symlink_info::check (char *path, const suffix_info *suffixes, unsigned opt)
             GetFileAttributes for a non-existant file an a Win9x share,
             GetLastError returns ERROR_INVALID_FUNCTION.  Go figure!
             Also, GetFileAttributes fails with ERROR_SHARING_VIOLATION
-            if the file is locked exclusively by another process.
+            if the file is locked exclusively by another process, or with
+            ERROR_ACCESS_DENIED if the file exists but the user has no right
+            to open the file with FILE_READ_ATTRIBUTES.
             If we don't special handle this here, the file is accidentally
             treated as non-existant. */
          DWORD win_error = GetLastError ();
          if (win_error == ERROR_INVALID_FUNCTION)
            win_error = ERROR_FILE_NOT_FOUND;
-         else if (win_error == ERROR_SHARING_VIOLATION)
+         else if (win_error == ERROR_SHARING_VIOLATION
+                  || win_error == ERROR_ACCESS_DENIED)
            {
+             /* This is easily converted to NT functions at one point,
+                see fhandler_base::fstat_by_name. */
+             WIN32_FIND_DATA data;
+             HANDLE f = FindFirstFile (suffix.path, &data);
+             if (f != INVALID_HANDLE_VALUE)
+               {
+                 FindClose (f);
+                 fileattr = data.dwFileAttributes;
+               }
+             else
+               fileattr = 0;
              ext_tacked_on = !!*ext_here;
-             fileattr = 0;
              goto file_not_symlink;
            }
          if (set_error (geterrno_from_win_error (win_error, EACCES)))