1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
10 int copy_fd(int ifd
, int ofd
)
14 ssize_t len
= xread(ifd
, buffer
, sizeof(buffer
));
18 return COPY_READ_ERROR
;
19 if (write_in_full(ofd
, buffer
, len
) < 0)
20 return COPY_WRITE_ERROR
;
25 static int copy_times(const char *dst
, const char *src
)
29 if (stat(src
, &st
) < 0)
31 times
.actime
= st
.st_atime
;
32 times
.modtime
= st
.st_mtime
;
33 if (utime(dst
, ×
) < 0)
38 int copy_file(const char *dst
, const char *src
, int mode
)
42 mode
= (mode
& 0111) ? 0777 : 0666;
43 if ((fdi
= open(src
, O_RDONLY
)) < 0)
45 if ((fdo
= open(dst
, O_WRONLY
| O_CREAT
| O_EXCL
, mode
)) < 0) {
49 status
= copy_fd(fdi
, fdo
);
52 error_errno("copy-fd: read returned");
54 case COPY_WRITE_ERROR
:
55 error_errno("copy-fd: write returned");
60 return error_errno("%s: close error", dst
);
62 if (!status
&& adjust_shared_perm(the_repository
, dst
))
68 int copy_file_with_time(const char *dst
, const char *src
, int mode
)
70 int status
= copy_file(dst
, src
, mode
);
72 return copy_times(dst
, src
);