| 36 | } |
| 37 | |
| 38 | int copy_file(const char *dst, const char *src, int mode) |
| 39 | { |
| 40 | int fdi, fdo, status; |
| 41 | |
| 42 | mode = (mode & 0111) ? 0777 : 0666; |
| 43 | if ((fdi = open(src, O_RDONLY)) < 0) |
| 44 | return fdi; |
| 45 | if ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) { |
| 46 | close(fdi); |
| 47 | return fdo; |
| 48 | } |
| 49 | status = copy_fd(fdi, fdo); |
| 50 | switch (status) { |
| 51 | case COPY_READ_ERROR: |
| 52 | error_errno("copy-fd: read returned"); |
| 53 | break; |
| 54 | case COPY_WRITE_ERROR: |
| 55 | error_errno("copy-fd: write returned"); |
| 56 | break; |
| 57 | } |
| 58 | close(fdi); |
| 59 | if (close(fdo) != 0) |
| 60 | return error_errno("%s: close error", dst); |
| 61 | |
| 62 | if (!status && adjust_shared_perm(the_repository, dst)) |
| 63 | return -1; |
| 64 | |
| 65 | return status; |
| 66 | } |
| 67 | |
| 68 | int copy_file_with_time(const char *dst, const char *src, int mode) |
| 69 | { |
no test coverage detected