Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Köplinger <alex.koeplinger@outlook.com>2019-10-29 20:42:36 +0300
committerGitHub <noreply@github.com>2019-10-29 20:42:36 +0300
commit6f27fe17ab89a2be3367105eaccf7ba673ec8041 (patch)
tree2c6b7dd518594912e2b3c1f631e43d53f8e7fa08 /src
parent82e3cdb19cab91a0a88db896c1e2cc43f0afb23c (diff)
Still check for futimens() result on desktop, remove unnecessary fstat() calls
Diffstat (limited to 'src')
-rw-r--r--src/Native/Unix/System.Native/pal_io.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/Native/Unix/System.Native/pal_io.c b/src/Native/Unix/System.Native/pal_io.c
index 37a9b417b8..c3b5aff83b 100644
--- a/src/Native/Unix/System.Native/pal_io.c
+++ b/src/Native/Unix/System.Native/pal_io.c
@@ -1266,8 +1266,8 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, intptr_t destinationFd)
return -1;
}
- // Then copy permissions. This fchmod() needs to happen prior to writing anything into
- // the file to avoid possiblyleaking any private data.
+ // Copy permissions. This fchmod() needs to happen prior to writing anything into
+ // the file to avoid possibly leaking any private data.
while ((ret = fchmod(outFd, sourceStat.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))) < 0 && errno == EINTR);
#if !TARGET_ANDROID
// On Android, we are not allowed to modify permissions, but the copy should still succeed;
@@ -1281,12 +1281,6 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, intptr_t destinationFd)
#if HAVE_SENDFILE_4
// If sendfile is available (Linux), try to use it, as the whole copy
// can be performed in the kernel, without lots of unnecessary copying.
- while ((ret = fstat_(inFd, &sourceStat)) < 0 && errno == EINTR);
- if (ret != 0)
- {
- return -1;
- }
-
// On 32-bit, if you use 64-bit offsets, the last argument of `sendfile' will be a
// `size_t' a 32-bit integer while the `st_size' field of the stat structure will be off64_t.
@@ -1334,26 +1328,30 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, intptr_t destinationFd)
// from the source file. First copy the file times.
// If futimes nor futimes are available on this platform, file times will
// not be copied over.
- while ((ret = fstat_(inFd, &sourceStat)) < 0 && errno == EINTR);
- if (ret == 0)
- {
#if HAVE_FUTIMENS
- // futimens is prefered because it has a higher resolution.
- struct timespec origTimes[2];
- origTimes[0].tv_sec = (time_t)sourceStat.st_atime;
- origTimes[0].tv_nsec = ST_ATIME_NSEC(&sourceStat);
- origTimes[1].tv_sec = (time_t)sourceStat.st_mtime;
- origTimes[1].tv_nsec = ST_MTIME_NSEC(&sourceStat);
- while ((ret = futimens(outFd, origTimes)) < 0 && errno == EINTR);
+ // futimens is prefered because it has a higher resolution.
+ struct timespec origTimes[2];
+ origTimes[0].tv_sec = (time_t)sourceStat.st_atime;
+ origTimes[0].tv_nsec = ST_ATIME_NSEC(&sourceStat);
+ origTimes[1].tv_sec = (time_t)sourceStat.st_mtime;
+ origTimes[1].tv_nsec = ST_MTIME_NSEC(&sourceStat);
+ while ((ret = futimens(outFd, origTimes)) < 0 && errno == EINTR);
#elif HAVE_FUTIMES
- struct timeval origTimes[2];
- origTimes[0].tv_sec = sourceStat.st_atime;
- origTimes[0].tv_usec = ST_ATIME_NSEC(&sourceStat) / 1000;
- origTimes[1].tv_sec = sourceStat.st_mtime;
- origTimes[1].tv_usec = ST_MTIME_NSEC(&sourceStat) / 1000;
- while ((ret = futimes(outFd, origTimes)) < 0 && errno == EINTR);
+ struct timeval origTimes[2];
+ origTimes[0].tv_sec = sourceStat.st_atime;
+ origTimes[0].tv_usec = ST_ATIME_NSEC(&sourceStat) / 1000;
+ origTimes[1].tv_sec = sourceStat.st_mtime;
+ origTimes[1].tv_usec = ST_MTIME_NSEC(&sourceStat) / 1000;
+ while ((ret = futimes(outFd, origTimes)) < 0 && errno == EINTR);
#endif
+
+#if !TARGET_ANDROID
+ // On Android, the copy should still succeed even if copying the file times didn't.
+ if (ret != 0)
+ {
+ return -1;
}
+#endif
return 0;
#endif // HAVE_FCOPYFILE