Skip to content

Commit

Permalink
Restore fchmod check in SystemNative_CopyFile and only ignore when it…
Browse files Browse the repository at this point in the history
… fails on android (#365)
  • Loading branch information
steveisok committed Oct 29, 2019
1 parent eb2575e commit 11501bf
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Native/Unix/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,23 +1258,6 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, intptr_t destinationFd)
struct stat_ sourceStat;
bool copied = false;

#if !MONODROID
// First, stat the source file.
while ((ret = fstat_(inFd, &sourceStat)) < 0 && errno == EINTR);
if (ret != 0)
{
// If we can't stat() it, then we likely don't have permission to read it.
return -1;
}

// Then copy permissions.
while ((ret = fchmod(outFd, sourceStat.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))) < 0 && errno == EINTR);
if (ret != 0)
{
return -1;
}
#endif

#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.
Expand All @@ -1284,7 +1267,6 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, intptr_t destinationFd)
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.
// So `size' will have to be `uint64_t'. In all other cases, it will be `size_t'.
Expand Down Expand Up @@ -1352,6 +1334,24 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, intptr_t destinationFd)
#endif
}

if (ret != 0)
{
return -1;
}

// Then copy permissions.
while ((ret = fchmod(outFd, sourceStat.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))) < 0 && errno == EINTR);

// We are ignoring the error on Android because in the case of external storage we are not allowed
// to modify permissions, but the copy should still succeed.
// https://github.com/mono/mono/issues/17133
#if !TARGET_ANDROID
if (ret != 0)
{
return -1;
}
#endif

return 0;
#endif // HAVE_FCOPYFILE
}
Expand Down

0 comments on commit 11501bf

Please sign in to comment.