* dir.cc (rmdir): Rearrange slightly to allow removing directories
even when R/O attribute is set.
This commit is contained in:
		| @@ -1,3 +1,8 @@ | |||||||
|  | Sat May 12 18:19:00 2001  Corinna Vinschen <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* dir.cc (rmdir): Rearrange slightly to allow removing directories | ||||||
|  | 	even when R/O attribute is set. | ||||||
|  |  | ||||||
| Fri May 11 16:53:38 2001  Christopher Faylor <cgf@cygnus.com> | Fri May 11 16:53:38 2001  Christopher Faylor <cgf@cygnus.com> | ||||||
|  |  | ||||||
| 	* external.cc (fillout_pinfo): Use correct pids. | 	* external.cc (fillout_pinfo): Use correct pids. | ||||||
|   | |||||||
| @@ -343,6 +343,19 @@ rmdir (const char *dir) | |||||||
|       goto done; |       goto done; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |   /* Is `dir' a directory? */ | ||||||
|  |   if (real_dir.file_attributes () == (DWORD) -1 || | ||||||
|  |       !(real_dir.file_attributes () & FILE_ATTRIBUTE_DIRECTORY)) | ||||||
|  |     { | ||||||
|  |       set_errno (ENOTDIR); | ||||||
|  |       goto done; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   /* Even own directories can't be removed if R/O attribute is set. */ | ||||||
|  |   if (real_dir.file_attributes () & FILE_ATTRIBUTE_READONLY) | ||||||
|  |     SetFileAttributes (real_dir.get_win32 (), real_dir.file_attributes () & | ||||||
|  |     					      ~FILE_ATTRIBUTE_READONLY); | ||||||
|  |  | ||||||
|   if (RemoveDirectoryA (real_dir.get_win32 ())) |   if (RemoveDirectoryA (real_dir.get_win32 ())) | ||||||
|     { |     { | ||||||
|       /* RemoveDirectory on a samba drive doesn't return an error if the |       /* RemoveDirectory on a samba drive doesn't return an error if the | ||||||
| @@ -353,21 +366,24 @@ rmdir (const char *dir) | |||||||
|       else |       else | ||||||
| 	res = 0; | 	res = 0; | ||||||
|     } |     } | ||||||
|   else if (GetLastError() == ERROR_ACCESS_DENIED) |  | ||||||
|     { |  | ||||||
|       /* Under Windows 9X or on a samba share, ERROR_ACCESS_DENIED is |  | ||||||
| 	 returned if you try to remove a file. On 9X the same error is |  | ||||||
| 	 returned if you try to remove a non-empty directory. */ |  | ||||||
|      if (real_dir.file_attributes () != (DWORD) -1 && |  | ||||||
| 	 !(real_dir.file_attributes () & FILE_ATTRIBUTE_DIRECTORY)) |  | ||||||
|        set_errno (ENOTDIR); |  | ||||||
|      else if (os_being_run != winNT) |  | ||||||
|        set_errno (ENOTEMPTY); |  | ||||||
|      else |  | ||||||
|        __seterrno (); |  | ||||||
|     } |  | ||||||
|   else |   else | ||||||
|     __seterrno (); |     { | ||||||
|  |       if (GetLastError() == ERROR_ACCESS_DENIED) | ||||||
|  |         { | ||||||
|  | 	  /* On 9X ERROR_ACCESS_DENIED is returned if you try to remove | ||||||
|  | 	     a non-empty directory. */ | ||||||
|  | 	  if (os_being_run != winNT) | ||||||
|  | 	    set_errno (ENOTEMPTY); | ||||||
|  | 	  else | ||||||
|  | 	    __seterrno (); | ||||||
|  | 	} | ||||||
|  |       else | ||||||
|  | 	__seterrno (); | ||||||
|  |  | ||||||
|  |       /* If directory still exists, restore R/O attribute. */ | ||||||
|  |       if (real_dir.file_attributes () & FILE_ATTRIBUTE_READONLY) | ||||||
|  | 	SetFileAttributes (real_dir.get_win32 (), real_dir.file_attributes ()); | ||||||
|  |     } | ||||||
|  |  | ||||||
| done: | done: | ||||||
|   syscall_printf ("%d = rmdir (%s)", res, dir); |   syscall_printf ("%d = rmdir (%s)", res, dir); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user