diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-03-05 14:34:32 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-03-05 14:34:32 +0200 |
| commit | 55ffebe37768b2b839f5501f76e77e89d9f91882 (patch) | |
| tree | c9275716290855fd909df22c4163bf7797da02b8 /src/fileops.c | |
| parent | 246eba80af31d25a1fb14e707f79374cf91f8bb7 (diff) | |
| download | libgit2-55ffebe37768b2b839f5501f76e77e89d9f91882.tar.gz | |
Fix creation of deeply-rooted references
Use a new `gitfo_creat_force` that will create the full path to a file
before creating it.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/fileops.c')
| -rw-r--r-- | src/fileops.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/src/fileops.c b/src/fileops.c index 7691129f6..76e689e8a 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -2,6 +2,29 @@ #include "fileops.h" #include <ctype.h> +static int force_path(const char *to) +{ + const int mode = 0755; /* or 0777 ? */ + int error = GIT_SUCCESS; + char target_folder_path[GIT_PATH_MAX]; + + error = git__dirname_r(target_folder_path, sizeof(target_folder_path), to); + if (error < GIT_SUCCESS) + return error; + + /* Does the containing folder exist? */ + if (gitfo_isdir(target_folder_path)) { + git__joinpath(target_folder_path, target_folder_path, ""); /* Ensure there's a trailing slash */ + + /* Let's create the tree structure */ + error = gitfo_mkdir_recurs(target_folder_path, mode); + if (error < GIT_SUCCESS) + return error; + } + + return GIT_SUCCESS; +} + int gitfo_open(const char *path, int flags) { int fd = open(path, flags | O_BINARY); @@ -14,6 +37,14 @@ int gitfo_creat(const char *path, int mode) return fd >= 0 ? fd : GIT_EOSERR; } +int gitfo_creat_force(const char *path, int mode) +{ + if (force_path(path) < GIT_SUCCESS) + return GIT_EOSERR; + + return gitfo_creat(path, mode); +} + int gitfo_read(git_file fd, void *buf, size_t cnt) { char *b = buf; @@ -167,23 +198,8 @@ int gitfo_mv(const char *from, const char *to) int gitfo_mv_force(const char *from, const char *to) { - const int mode = 0755; /* or 0777 ? */ - int error = GIT_SUCCESS; - char target_folder_path[GIT_PATH_MAX]; - - error = git__dirname_r(target_folder_path, sizeof(target_folder_path), to); - if (error < GIT_SUCCESS) - return error; - - /* Does the containing folder exist? */ - if (gitfo_isdir(target_folder_path)) { - git__joinpath(target_folder_path, target_folder_path, ""); /* Ensure there's a trailing slash */ - - /* Let's create the tree structure */ - error = gitfo_mkdir_recurs(target_folder_path, mode); - if (error < GIT_SUCCESS) - return error; - } + if (force_path(to) < GIT_SUCCESS) + return GIT_EOSERR; return gitfo_mv(from, to); } |
