Hi list,
apr_file_copy does not copies permissions from source if the destination
already exists, even when the flag APR_FILE_SOURCE_PERMS is set.
I made a quick test by creating 3 files with the following permissions:
-rwx------. test1.txt
-rwxrwx---. test2.txt
-rwxrwx---. test3.txt
then I copied test1.txt over test3.txt, using apr_file_copy with the
APR_FILE_SOURCE_PERMS flag, so I was expecting that test3.txt permissions
would be copied from test1.txt, but that didn't happened. The content of
the file was copied correctly, I can see that test3.txt now has the content
of test1.txt, however the permissions were not copied from the source.
Is this the expected behaviour? should documentation warn that if the
destination already exists, then permissions will not be copied even with
that flag?
// TEST PROGRAM
apr_status_t rc = APR_SUCCESS; /* APR error code */
apr_file_t *file = NULL; /* file
handle */
apr_pool_t *pool; /**< memory pool */
apr_pool_create(&pool,NULL);
if(APR_SUCCESS != (rc=apr_file_open(&file,"test1.txt",APR_WRITE|APR_
CREATE|APR_TRUNCATE,(apr_fileperms_t)APR_UREAD|APR_UWRITE|APR_UEXECUTE,pool)))
{
return 1;
}
if(APR_SUCCESS != (rc=apr_file_write_full(file,(
void*)"1",(apr_size_t)1,NULL))) {
SYS_XLOG_ERROR("Error writing to file: %s. rc:
%pm","test1.txt",&rc);
return 1;
}
apr_file_close(file);
printf("test1.txt created with permissions: APR_UREAD|APR_UWRITE|APR_
UEXECUTE\n");
if(APR_SUCCESS != (rc=apr_file_open(&file,"test2.txt",APR_WRITE|APR_
CREATE|APR_TRUNCATE,(apr_fileperms_t)APR_UREAD|APR_
UWRITE|APR_UEXECUTE|APR_GREAD|APR_GWRITE|APR_GEXECUTE,pool))) {
return 1;
}
if(APR_SUCCESS != (rc=apr_file_write_full(file,(
void*)"2",(apr_size_t)1,NULL))) {
return 1;
}
apr_file_close(file);
printf("test2.txt created with permissions: APR_UREAD|APR_UWRITE|APR_
UEXECUTE|APR_GREAD|APR_GWRITE|APR_GEXECUTE\n");
if(APR_SUCCESS != (rc=apr_file_open(&file,"test3.txt",APR_WRITE|APR_
CREATE|APR_TRUNCATE,(apr_fileperms_t)APR_UREAD|APR_
UWRITE|APR_UEXECUTE|APR_GREAD|APR_GWRITE|APR_GEXECUTE,pool))) {
return 1;
}
if(APR_SUCCESS != (rc=apr_file_write_full(file,(
void*)"3",(apr_size_t)1,NULL))) {
return 1;
}
apr_file_close(file);
printf("test3.txt created with permissions: APR_UREAD|APR_UWRITE|APR_
UEXECUTE|APR_GREAD|APR_GWRITE|APR_GEXECUTE\n");
if(APR_SUCCESS !=
(rc=apr_file_copy("test1.txt","test3.txt",APR_FILE_SOURCE_PERMS,pool)))
{
return 1;
}
printf("copied test1.txt to test3.txt\n");
return 0;