Ticket #72: 13935-copy_file_file_chmod.patch

File 13935-copy_file_file_chmod.patch, 1.8 KB (added by slavazanko, 15 years ago)

added by ptsekov

  • src/file.c

    RCS file: /cvsroot/mc/mc/src/file.c,v
    retrieving revision 1.149
    diff -u -p -r1.149 file.c
    copy_file_file (FileOpContext *ctx, cons 
    474474    int return_status, temp_status; 
    475475    struct timeval tv_transfer_start; 
    476476    int dst_status = DEST_NONE; /* 1 if the file is not fully copied */ 
     477    int open_flags; 
    477478 
    478479    /* FIXME: We should not be using global variables! */ 
    479480    ctx->do_reget = 0; 
    copy_file_file (FileOpContext *ctx, cons 
    606607    utb.modtime = sb.st_mtime; 
    607608    file_size = sb.st_size; 
    608609 
    609     /* Create the new regular file with small permissions initially, 
    610        do not create a security hole.  FIXME: You have security hole 
    611        here, btw. Imagine copying to /tmp and symlink attack :-( */ 
    612  
    613     while ((dest_desc = mc_open (dst_path, O_WRONLY | (ctx->do_append ? 
    614             O_APPEND : (O_CREAT | O_TRUNC)), 0600)) < 0) { 
     610    open_flags = O_WRONLY; 
     611    if (dst_exists != 0) { 
     612        if (ctx->do_append != 0) 
     613            open_flags |= O_APPEND; 
     614        else 
     615            open_flags |= O_CREAT | O_TRUNC; 
     616    } else { 
     617        open_flags |= O_CREAT | O_EXCL; 
     618    } 
     619    while ((dest_desc = mc_open (dst_path, open_flags, src_mode)) < 0) { 
     620        if (errno == EEXIST) { 
     621            goto ret; 
     622        } 
    615623        return_status = file_error ( 
    616624                _(" Cannot create target file \"%s\" \n %s "), dst_path); 
    617625        if (return_status == FILE_RETRY) 
    copy_file_file (FileOpContext *ctx, cons 
    790798            } 
    791799        } 
    792800 
    793         if (!appending) { 
     801        if (!appending && ctx->preserve) { 
    794802            while (mc_chmod (dst_path, (src_mode & ctx->umask_kill))) { 
    795803                temp_status = file_error ( 
    796804                        _(" Cannot chmod target file \"%s\" \n %s "), dst_path);