Do not mmap-copy the whole thing; just use copy_fd()
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 29, 2005 at 13:11 UTC
52e4478dbd3425332ed4ef6a4cadeb034ee8c4b6
1 file changed
+10
-18
local-fetch.c
+10
-18
@@ -83,31 +83,23 @@ static int copy_file(const char *source, char *dest, const char *hex,
83
}
84
}
85
if (use_filecopy) {
86
- int ifd, ofd, status;
87
- struct stat st;
88
- void *map;
86
+ int ifd, ofd, status = 0;
87
+
88
ifd = open(source, O_RDONLY);
90
- if (ifd < 0 || fstat(ifd, &st) < 0) {
91
- int err = errno;
92
- if (ifd >= 0)
93
- close(ifd);
94
- if (!warn_if_not_exists && err == ENOENT)
89
+ if (ifd < 0) {
90
+ if (!warn_if_not_exists && errno == ENOENT)
91
return -1;
92
fprintf(stderr, "cannot open %s\n", source);
93
return -1;
94
}
99
- map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0);
100
- close(ifd);
101
- if (map == MAP_FAILED) {
102
- fprintf(stderr, "cannot mmap %s\n", source);
95
+ ofd = open(dest, O_WRONLY | O_CREAT | O_EXCL, 0666);
96
+ if (ofd < 0) {
97
+ fprintf(stderr, "cannot open %s\n", dest);
98
+ close(ifd);
99
return -1;
100
}
105
- ofd = open(dest, O_WRONLY | O_CREAT | O_EXCL, 0666);
106
- status = ((ofd < 0) ||
107
- (write(ofd, map, st.st_size) != st.st_size));
108
- munmap(map, st.st_size);
109
- if (ofd >= 0)
110
- close(ofd);
101
+ status = copy_fd(ifd, ofd);
102
+ close(ofd);
103
if (status)
104
fprintf(stderr, "cannot write %s\n", dest);
105
else