]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: rename: use FILE_RENAME_POSIX_SEMANTICS if available
authorCorinna Vinschen <corinna@vinschen.de>
Wed, 9 Jan 2019 14:47:43 +0000 (15:47 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Wed, 9 Jan 2019 14:47:43 +0000 (15:47 +0100)
starting with W10 1709 on local NTFS drives

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/release/2.12.0
winsup/cygwin/syscalls.cc
winsup/doc/new-features.xml

index 81a55b58d7e0871344a74f357674a73a91fb061a..b772782383e7f000d340f6e951f70883ac45ae40 100644 (file)
@@ -37,6 +37,10 @@ What changed:
   Deleting an in-use file now actually removes the file, rather than moving
   it to the recycler bin.
 
+- Use the new POSIX rename semantics on NTFS starting with Windows 10 1709.
+  Renaming a file to another in-use file now actually removes the other file,
+  rather than moving it to the recycler bin.
+
 - open(..., O_TMPFILE) now moves the file to the trash bin immediately,
   to free the parent directory.
 
index 78ac44bdcbecc145389122628dd5f4fa0ba83036..4f91f4b48a2b2de496c7be514a416cb4c2f3c15b 100644 (file)
@@ -2216,6 +2216,7 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
   path_conv oldpc, newpc, new2pc, *dstpc, *removepc = NULL;
   bool old_dir_requested = false, new_dir_requested = false;
   bool old_explicit_suffix = false, new_explicit_suffix = false;
+  bool use_posix_semantics;
   bool noreplace = at2flags & RENAME_NOREPLACE;
   size_t olen, nlen;
   bool equal_path;
@@ -2511,10 +2512,18 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
          __leave;
        }
 
+      /* POSIX semantics only on local NTFS drives. */
+      use_posix_semantics = wincap.has_posix_file_info ()
+                           && !oldpc.isremote ()
+                           && oldpc.fs_is_ntfs ();
+
       /* Opening the file must be part of the transaction.  It's not sufficient
         to call only NtSetInformationFile under the transaction.  Therefore we
-        have to start the transaction here, if necessary. */
-      if ((dstpc->fs_flags () & FILE_SUPPORTS_TRANSACTIONS)
+        have to start the transaction here, if necessary.  Don't start
+        transaction on W10 1709 or later on local NTFS.  Use POSIX semantics
+        instead. */
+      if (!use_posix_semantics
+         && (dstpc->fs_flags () & FILE_SUPPORTS_TRANSACTIONS)
          && (dstpc->isdir ()
              || (!removepc && dstpc->has_attribute (FILE_ATTRIBUTE_READONLY))))
        start_transaction (old_trans, trans);
@@ -2578,6 +2587,9 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
          __leave;
        }
 
+      if (use_posix_semantics)
+       goto skip_pre_W10_checks;
+
       /* Renaming a dir to another, existing dir fails always, even if
         ReplaceIfExists is set to TRUE and the existing dir is empty.  So
         we have to remove the destination dir first.  This also covers the
@@ -2619,6 +2631,8 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
            }
        }
 
+skip_pre_W10_checks:
+
       /* SUSv3: If the old argument and the new argument resolve to the same
         existing file, rename() shall return successfully and perform no
         other action.
@@ -2666,7 +2680,13 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
          __leave;
        }
       pfri = (PFILE_RENAME_INFORMATION) tp.w_get ();
-      pfri->ReplaceIfExists = !noreplace;
+      if (use_posix_semantics)
+       pfri->Flags = noreplace ? 0
+                               : (FILE_RENAME_REPLACE_IF_EXISTS
+                                  | FILE_RENAME_POSIX_SEMANTICS
+                                  | FILE_RENAME_IGNORE_READONLY_ATTRIBUTE);
+      else
+       pfri->ReplaceIfExists = !noreplace;
       pfri->RootDirectory = NULL;
       pfri->FileNameLength = dstpc->get_nt_native_path ()->Length;
       memcpy (&pfri->FileName,  dstpc->get_nt_native_path ()->Buffer,
@@ -2677,7 +2697,9 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
         ERROR_ALREADY_EXISTS ==> Cygwin error EEXIST. */
       status = NtSetInformationFile (fh, &io, pfri,
                                     sizeof *pfri + pfri->FileNameLength,
-                                    FileRenameInformation);
+                                    use_posix_semantics
+                                    ? FileRenameInformationEx
+                                    : FileRenameInformation);
       /* This happens if the access rights don't allow deleting the destination.
         Even if the handle to the original file is opened with BACKUP
         and/or RECOVERY, these flags don't apply to the destination of the
index f84a9c44385480a4ba5514965631a2d527f2efe7..6af7270f9ea22cc819681a2961f82100c39f6273 100644 (file)
@@ -54,6 +54,12 @@ all clocks, except CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID.
 clock_setres is a no-op now.
 </para></listitem>
 
+<listitem><para>
+Use the new POSIX rename semantics on NTFS starting with Windows 10
+1709.  Renaming a file to another in-use file now actually removes the
+other file, rather than moving it to the recycler bin.
+</para></listitem>
+
 <listitem><para>
 Use the new POSIX unlink semantics on NTFS starting with Windows 10
 1709.  Deleting an in-use file now actually removes the file, rather
This page took 0.039521 seconds and 5 git commands to generate.