Do not mmap-copy the whole thing; just use copy_fd()
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
0ffdbbfe36
commit
52e4478dbd
@ -83,31 +83,23 @@ static int copy_file(const char *source, char *dest, const char *hex,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (use_filecopy) {
|
if (use_filecopy) {
|
||||||
int ifd, ofd, status;
|
int ifd, ofd, status = 0;
|
||||||
struct stat st;
|
|
||||||
void *map;
|
|
||||||
ifd = open(source, O_RDONLY);
|
ifd = open(source, O_RDONLY);
|
||||||
if (ifd < 0 || fstat(ifd, &st) < 0) {
|
if (ifd < 0) {
|
||||||
int err = errno;
|
if (!warn_if_not_exists && errno == ENOENT)
|
||||||
if (ifd >= 0)
|
|
||||||
close(ifd);
|
|
||||||
if (!warn_if_not_exists && err == ENOENT)
|
|
||||||
return -1;
|
return -1;
|
||||||
fprintf(stderr, "cannot open %s\n", source);
|
fprintf(stderr, "cannot open %s\n", source);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0);
|
ofd = open(dest, O_WRONLY | O_CREAT | O_EXCL, 0666);
|
||||||
close(ifd);
|
if (ofd < 0) {
|
||||||
if (map == MAP_FAILED) {
|
fprintf(stderr, "cannot open %s\n", dest);
|
||||||
fprintf(stderr, "cannot mmap %s\n", source);
|
close(ifd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ofd = open(dest, O_WRONLY | O_CREAT | O_EXCL, 0666);
|
status = copy_fd(ifd, ofd);
|
||||||
status = ((ofd < 0) ||
|
close(ofd);
|
||||||
(write(ofd, map, st.st_size) != st.st_size));
|
|
||||||
munmap(map, st.st_size);
|
|
||||||
if (ofd >= 0)
|
|
||||||
close(ofd);
|
|
||||||
if (status)
|
if (status)
|
||||||
fprintf(stderr, "cannot write %s\n", dest);
|
fprintf(stderr, "cannot write %s\n", dest);
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user