summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0312600)
raw | patch | inline | side by side (parent: 0312600)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 11 Oct 2005 06:22:01 +0000 (23:22 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 11 Oct 2005 06:22:01 +0000 (23:22 -0700) |
The http commit walker cannot use the same temporary file
creation code because it needs to use predictable temporary
filename for partial fetch continuation purposes, but the code
to move the temporary file to the final location should be
usable from the ordinary object creation codepath.
Export move_temp_to_file from sha1_file.c and use it, while
losing the custom relink_or_rename function from http-fetch.c.
Also the temporary object file creation part needs to make sure
the leading path exists, in preparation of the really lazy
fan-out directory creation.
Signed-off-by: Junio C Hamano <junkio@cox.net>
creation code because it needs to use predictable temporary
filename for partial fetch continuation purposes, but the code
to move the temporary file to the final location should be
usable from the ordinary object creation codepath.
Export move_temp_to_file from sha1_file.c and use it, while
losing the custom relink_or_rename function from http-fetch.c.
Also the temporary object file creation part needs to make sure
the leading path exists, in preparation of the really lazy
fan-out directory creation.
Signed-off-by: Junio C Hamano <junkio@cox.net>
cache.h | patch | blob | history | |
http-fetch.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
index 0571282e8cb4d47e6559d2d8897f557a6f659491..64cbcac5b85ba296b85899a97e805f7fcdc4bc27 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -223,6 +223,7 @@ extern int read_tree(void *buffer, unsigned long size, int stage, const char **p
extern int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
size_t bufsize, size_t *bufposn);
extern int write_sha1_to_fd(int fd, const unsigned char *sha1);
+extern int move_temp_to_file(const char *tmpfile, char *filename);
extern int has_sha1_pack(const unsigned char *sha1);
extern int has_sha1_file(const unsigned char *sha1);
diff --git a/http-fetch.c b/http-fetch.c
index 5d0e3e3923c0399e9b4e650c2ee88368dff441ce..5821c9e5e90e5951f760fbfad25544251c2ead28 100644 (file)
--- a/http-fetch.c
+++ b/http-fetch.c
return size;
}
-int relink_or_rename(char *old, char *new) {
- int ret;
-
- ret = link(old, new);
- if (ret < 0) {
- /* Same Coda hack as in write_sha1_file(sha1_file.c) */
- ret = errno;
- if (ret == EXDEV && !rename(old, new))
- return 0;
- }
- unlink(old);
- if (ret) {
- if (ret != EEXIST)
- return ret;
- }
-
- return 0;
-}
-
#ifdef USE_CURL_MULTI
void process_curl_messages();
void process_request_queue();
request->local = open(request->tmpfile,
O_WRONLY | O_CREAT | O_EXCL, 0666);
+ /* This could have failed due to the "lazy directory creation";
+ * try to mkdir the last path component.
+ */
+ if (request->local < 0 && errno == ENOENT) {
+ char *dir = strrchr(request->tmpfile, '/');
+ if (dir) {
+ *dir = 0;
+ mkdir(request->tmpfile, 0777);
+ *dir = '/';
+ }
+ request->local = open(request->tmpfile,
+ O_WRONLY | O_CREAT | O_EXCL, 0666);
+ }
+
if (request->local < 0) {
request->state = ABORTED;
error("Couldn't create temporary file %s for %s: %s\n",
return;
}
request->rename =
- relink_or_rename(request->tmpfile, request->filename);
+ move_temp_to_file(request->tmpfile, request->filename);
if (request->rename == 0)
pull_say("got %s\n", sha1_to_hex(request->sha1));
char *filename;
char *url;
char tmpfile[PATH_MAX];
- int ret;
long prev_posn = 0;
char range[RANGE_HEADER_SIZE];
struct curl_slist *range_header = NULL;
fclose(indexfile);
- ret = relink_or_rename(tmpfile, filename);
- if (ret)
- return error("unable to write index filename %s: %s",
- filename, strerror(ret));
-
- return 0;
+ return move_temp_to_file(tmpfile, filename);
}
static int setup_index(struct alt_base *repo, unsigned char *sha1)
fclose(packfile);
- ret = relink_or_rename(tmpfile, filename);
+ ret = move_temp_to_file(tmpfile, filename);
if (ret)
- return error("unable to write pack filename %s: %s",
- filename, strerror(ret));
+ return ret;
lst = &repo->packs;
while (*lst != target)
diff --git a/sha1_file.c b/sha1_file.c
index baaa4c00da50342a7db8064dadf7f963b0e2e679..6e3ea232eecc0f190925568ecb86fb24c93e6c94 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
/*
* Move the just written object into its final resting place
*/
-static int move_temp_to_file(const char *tmpfile, char *filename)
+int move_temp_to_file(const char *tmpfile, char *filename)
{
int ret = link_temp_to_file(tmpfile, filename);
if (ret) {