]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Make __gnat_copy_attribs non-blocking on windows
authorTonu Naks <naks@adacore.com>
Wed, 26 Nov 2025 12:24:19 +0000 (12:24 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 29 May 2026 08:49:47 +0000 (10:49 +0200)
gcc/ada/ChangeLog:

* adaint.c (__gnat_copy_attribs): use GetFileAttributesEx to
to fetch attributes.

gcc/ada/adaint.c

index 7147b03f5bde97f9894b97e6c8574a33dcc49d18..133807b8b567a2c4a5260fb6db1c1ad296ee0acd 100644 (file)
@@ -3240,41 +3240,28 @@ __gnat_copy_attribs (char *from ATTRIBUTE_UNUSED, char *to ATTRIBUTE_UNUSED,
   TCHAR wfrom [GNAT_MAX_PATH_LEN + 2];
   TCHAR wto [GNAT_MAX_PATH_LEN + 2];
   BOOL res;
-  FILETIME fct, flat, flwt;
-  HANDLE hfrom, hto;
+  HANDLE hto;
 
   S2WSC (wfrom, from, GNAT_MAX_PATH_LEN + 2);
   S2WSC (wto, to, GNAT_MAX_PATH_LEN + 2);
 
-  /*  Do we need to copy the timestamp ? */
+  WIN32_FILE_ATTRIBUTE_DATA info;
+  res = GetFileAttributesEx(wfrom, GetFileExInfoStandard, &info);
+  if (res == 0)
+    return -1;
 
   if (mode != 2) {
-     /* retrieve from times */
-
-     hfrom = CreateFile
-       (wfrom, GENERIC_READ, 0, NULL, OPEN_EXISTING,
-        FILE_ATTRIBUTE_NORMAL, NULL);
-
-     if (hfrom == INVALID_HANDLE_VALUE)
-       return -1;
-
-     res = GetFileTime (hfrom, &fct, &flat, &flwt);
-
-     CloseHandle (hfrom);
-
-     if (res == 0)
-       return -1;
-
-     /* retrieve from times */
+     /* Mode is not "None", copy timestamps */
 
      hto = CreateFile
-       (wto, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
+       (wto, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
         FILE_ATTRIBUTE_NORMAL, NULL);
 
      if (hto == INVALID_HANDLE_VALUE)
        return -1;
 
-     res = SetFileTime (hto, NULL, &flat, &flwt);
+     res = SetFileTime
+       (hto, NULL, &info.ftCreationTime, &info.ftLastAccessTime);
 
      CloseHandle (hto);
 
@@ -3282,20 +3269,14 @@ __gnat_copy_attribs (char *from ATTRIBUTE_UNUSED, char *to ATTRIBUTE_UNUSED,
        return -1;
   }
 
-  /* Do we need to copy the permissions ? */
-  /* Set file attributes in full mode. */
-
-  if (mode != 0)
-    {
-      DWORD attribs = GetFileAttributes (wfrom);
+  if (mode != 0) {
+    /* Mode is not "Time_Stamps", copy file attributes. */
 
-      if (attribs == INVALID_FILE_ATTRIBUTES)
-       return -1;
+    res = SetFileAttributes (wto, info.dwFileAttributes);
 
-      res = SetFileAttributes (wto, attribs);
-      if (res == 0)
-       return -1;
-    }
+    if (res == 0)
+      return -1;
+  }
 
   return 0;