summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-03-03 19:53:17 +0200
committerVicent Marti <tanoku@gmail.com>2011-03-03 20:23:51 +0200
commit19a30a3f6e15da184fc449315314af666f2082bf (patch)
treec9263fef3e6fea67f07405057777057684f9b6a0 /src/fileops.c
parent6b02b215169d493abe35d8036c3cf687521e08a5 (diff)
downloadlibgit2-19a30a3f6e15da184fc449315314af666f2082bf.tar.gz
Add new move function, `gitfo_mv_force`
Forces a move by creating the folder for the destination file, if it doesn't exist. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 9938011d7..7691129f6 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -142,7 +142,7 @@ void gitfo_free_buf(gitfo_buf *obj)
obj->data = NULL;
}
-int gitfo_move_file(char *from, char *to)
+int gitfo_mv(const char *from, const char *to)
{
#ifdef GIT_WIN32
/*
@@ -165,6 +165,29 @@ int gitfo_move_file(char *from, char *to)
#endif
}
+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;
+ }
+
+ return gitfo_mv(from, to);
+}
+
int gitfo_map_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
{
if (git__mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin) < GIT_SUCCESS)