Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-07-04 13:43:34 +0400
committerVicent Marti <tanoku@gmail.com>2011-07-05 04:04:03 +0400
commitf79026b4912bcd2336667f4c1663c06e233f0b32 (patch)
tree645b776032e924b587fad986aa3f3dc08c98d4c5 /src/filebuf.c
parent678e9e045becdc5d75f2ce2259ed01c3531ee181 (diff)
fileops: Cleanup
Cleaned up the structure of the whole OS-abstraction layer. fileops.c now contains a set of utility methods for file management used by the library. These are abstractions on top of the original POSIX calls. There's a new file called `posix.c` that contains emulations/reimplementations of all the POSIX calls the library uses. These are prefixed with `p_`. There's a specific posix file for each platform (win32 and unix). All the path-related methods have been moved from `utils.c` to `path.c` and have their own prefix.
Diffstat (limited to 'src/filebuf.c')
-rw-r--r--src/filebuf.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/filebuf.c b/src/filebuf.c
index ea5599b6d..acfdcd141 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -32,39 +32,39 @@ static const size_t WRITE_BUFFER_SIZE = (4096 * 2);
static int lock_file(git_filebuf *file, int flags)
{
- if (gitfo_exists(file->path_lock) == 0) {
+ if (git_futils_exists(file->path_lock) == 0) {
if (flags & GIT_FILEBUF_FORCE)
- gitfo_unlink(file->path_lock);
+ p_unlink(file->path_lock);
else
return git__throw(GIT_EOSERR, "Failed to lock file");
}
/* create path to the file buffer is required */
if (flags & GIT_FILEBUF_FORCE) {
- file->fd = gitfo_creat_locked_force(file->path_lock, 0644);
+ file->fd = git_futils_creat_locked_withpath(file->path_lock, 0644);
} else {
- file->fd = gitfo_creat_locked(file->path_lock, 0644);
+ file->fd = git_futils_creat_locked(file->path_lock, 0644);
}
if (file->fd < 0)
return git__throw(GIT_EOSERR, "Failed to create lock");
- if ((flags & GIT_FILEBUF_APPEND) && gitfo_exists(file->path_original) == 0) {
+ if ((flags & GIT_FILEBUF_APPEND) && git_futils_exists(file->path_original) == 0) {
git_file source;
char buffer[2048];
size_t read_bytes;
- source = gitfo_open(file->path_original, O_RDONLY);
+ source = p_open(file->path_original, O_RDONLY);
if (source < 0)
return git__throw(GIT_EOSERR, "Failed to lock file. Could not open %s", file->path_original);
- while ((read_bytes = gitfo_read(source, buffer, 2048)) > 0) {
- gitfo_write(file->fd, buffer, read_bytes);
+ while ((read_bytes = p_read(source, buffer, 2048)) > 0) {
+ p_write(file->fd, buffer, read_bytes);
if (file->digest)
git_hash_update(file->digest, buffer, read_bytes);
}
- gitfo_close(source);
+ p_close(source);
}
return GIT_SUCCESS;
@@ -73,10 +73,10 @@ static int lock_file(git_filebuf *file, int flags)
void git_filebuf_cleanup(git_filebuf *file)
{
if (file->fd >= 0)
- gitfo_close(file->fd);
+ p_close(file->fd);
- if (file->fd >= 0 && file->path_lock && gitfo_exists(file->path_lock) == GIT_SUCCESS)
- gitfo_unlink(file->path_lock);
+ if (file->fd >= 0 && file->path_lock && git_futils_exists(file->path_lock) == GIT_SUCCESS)
+ p_unlink(file->path_lock);
if (file->digest)
git_hash_free_ctx(file->digest);
@@ -102,7 +102,7 @@ static int write_normal(git_filebuf *file, const void *source, size_t len)
int result = 0;
if (len > 0) {
- result = gitfo_write(file->fd, (void *)source, len);
+ result = p_write(file->fd, (void *)source, len);
if (file->digest)
git_hash_update(file->digest, source, len);
}
@@ -130,7 +130,7 @@ static int write_deflate(git_filebuf *file, const void *source, size_t len)
have = file->buf_size - zs->avail_out;
- if (gitfo_write(file->fd, file->z_buf, have) < GIT_SUCCESS)
+ if (p_write(file->fd, file->z_buf, have) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to write to file");
} while (zs->avail_out == 0);
@@ -200,7 +200,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
char tmp_path[GIT_PATH_MAX];
/* Open the file as temporary for locking */
- file->fd = gitfo_mktemp(tmp_path, path);
+ file->fd = git_futils_mktmp(tmp_path, path);
if (file->fd < 0) {
error = GIT_EOSERR;
goto cleanup;
@@ -283,10 +283,10 @@ int git_filebuf_commit(git_filebuf *file)
if ((error = flush_buffer(file)) < GIT_SUCCESS)
goto cleanup;
- gitfo_close(file->fd);
+ p_close(file->fd);
file->fd = -1;
- error = gitfo_mv(file->path_lock, file->path_original);
+ error = git_futils_mv_atomic(file->path_lock, file->path_original);
cleanup:
git_filebuf_cleanup(file);