Commit f79026b4 by Vicent Marti

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.
parent 678e9e04
...@@ -91,9 +91,9 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat ...@@ -91,9 +91,9 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
if (repo->path_workdir == NULL) if (repo->path_workdir == NULL)
return git__throw(GIT_ENOTFOUND, "Failed to create blob. (No working directory found)"); return git__throw(GIT_ENOTFOUND, "Failed to create blob. (No working directory found)");
git__joinpath(full_path, repo->path_workdir, path); git_path_join(full_path, repo->path_workdir, path);
error = gitfo_lstat(full_path, &st); error = p_lstat(full_path, &st);
if (error < 0) { if (error < 0) {
return git__throw(GIT_EOSERR, "Failed to stat blob. %s", strerror(errno)); return git__throw(GIT_EOSERR, "Failed to stat blob. %s", strerror(errno));
} }
...@@ -102,12 +102,12 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat ...@@ -102,12 +102,12 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
size = st.st_size; size = st.st_size;
if (!islnk) if (!islnk)
if ((fd = gitfo_open(full_path, O_RDONLY)) < 0) if ((fd = p_open(full_path, O_RDONLY)) < 0)
return git__throw(GIT_ENOTFOUND, "Failed to create blob. Could not open '%s'", full_path); return git__throw(GIT_ENOTFOUND, "Failed to create blob. Could not open '%s'", full_path);
if ((error = git_odb_open_wstream(&stream, repo->db, (size_t)size, GIT_OBJ_BLOB)) < GIT_SUCCESS) { if ((error = git_odb_open_wstream(&stream, repo->db, (size_t)size, GIT_OBJ_BLOB)) < GIT_SUCCESS) {
if (!islnk) if (!islnk)
gitfo_close(fd); p_close(fd);
return git__rethrow(error, "Failed to create blob"); return git__rethrow(error, "Failed to create blob");
} }
...@@ -115,13 +115,13 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat ...@@ -115,13 +115,13 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
ssize_t read_len; ssize_t read_len;
if (!islnk) if (!islnk)
read_len = gitfo_read(fd, buffer, sizeof(buffer)); read_len = p_read(fd, buffer, sizeof(buffer));
else else
read_len = gitfo_readlink(full_path, buffer, sizeof(buffer)); read_len = p_readlink(full_path, buffer, sizeof(buffer));
if (read_len < 0) { if (read_len < 0) {
if (!islnk) if (!islnk)
gitfo_close(fd); p_close(fd);
stream->free(stream); stream->free(stream);
return git__throw(GIT_EOSERR, "Failed to create blob. Can't read full file"); return git__throw(GIT_EOSERR, "Failed to create blob. Can't read full file");
} }
...@@ -133,7 +133,7 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat ...@@ -133,7 +133,7 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
error = stream->finalize_write(oid, stream); error = stream->finalize_write(oid, stream);
stream->free(stream); stream->free(stream);
if (!islnk) if (!islnk)
gitfo_close(fd); p_close(fd);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create blob"); return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create blob");
} }
......
...@@ -333,9 +333,9 @@ int git_config_find_global(char *global_config_path) ...@@ -333,9 +333,9 @@ int git_config_find_global(char *global_config_path)
if (home == NULL) if (home == NULL)
return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory"); return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory");
git__joinpath(global_config_path, home, GIT_CONFIG_FILENAME); git_path_join(global_config_path, home, GIT_CONFIG_FILENAME);
if (gitfo_exists(global_config_path) < GIT_SUCCESS) if (git_futils_exists(global_config_path) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist"); return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist");
return GIT_SUCCESS; return GIT_SUCCESS;
......
...@@ -89,7 +89,7 @@ typedef struct { ...@@ -89,7 +89,7 @@ typedef struct {
cvar_t_list var_list; cvar_t_list var_list;
struct { struct {
gitfo_buf buffer; git_fbuffer buffer;
char *read_ptr; char *read_ptr;
int line_number; int line_number;
int eof; int eof;
...@@ -278,7 +278,7 @@ static int config_open(git_config_file *cfg) ...@@ -278,7 +278,7 @@ static int config_open(git_config_file *cfg)
int error; int error;
diskfile_backend *b = (diskfile_backend *)cfg; diskfile_backend *b = (diskfile_backend *)cfg;
error = gitfo_read_file(&b->reader.buffer, b->file_path); error = git_futils_readbuffer(&b->reader.buffer, b->file_path);
if(error < GIT_SUCCESS) if(error < GIT_SUCCESS)
goto cleanup; goto cleanup;
...@@ -286,13 +286,13 @@ static int config_open(git_config_file *cfg) ...@@ -286,13 +286,13 @@ static int config_open(git_config_file *cfg)
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
gitfo_free_buf(&b->reader.buffer); git_futils_freebuffer(&b->reader.buffer);
return error; return error;
cleanup: cleanup:
cvar_list_free(&b->var_list); cvar_list_free(&b->var_list);
gitfo_free_buf(&b->reader.buffer); git_futils_freebuffer(&b->reader.buffer);
return git__rethrow(error, "Failed to open config"); return git__rethrow(error, "Failed to open config");
} }
...@@ -921,7 +921,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var) ...@@ -921,7 +921,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
const char *pre_end = NULL, *post_start = NULL; const char *pre_end = NULL, *post_start = NULL;
/* We need to read in our own config file */ /* We need to read in our own config file */
error = gitfo_read_file(&cfg->reader.buffer, cfg->file_path); error = git_futils_readbuffer(&cfg->reader.buffer, cfg->file_path);
if (error < GIT_SUCCESS) { if (error < GIT_SUCCESS) {
return git__rethrow(error, "Failed to read existing config file %s", cfg->file_path); return git__rethrow(error, "Failed to read existing config file %s", cfg->file_path);
} }
...@@ -1068,7 +1068,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var) ...@@ -1068,7 +1068,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
else else
error = git_filebuf_commit(&file); error = git_filebuf_commit(&file);
gitfo_free_buf(&cfg->reader.buffer); git_futils_freebuffer(&cfg->reader.buffer);
return error; return error;
} }
......
...@@ -32,39 +32,39 @@ static const size_t WRITE_BUFFER_SIZE = (4096 * 2); ...@@ -32,39 +32,39 @@ static const size_t WRITE_BUFFER_SIZE = (4096 * 2);
static int lock_file(git_filebuf *file, int flags) 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) if (flags & GIT_FILEBUF_FORCE)
gitfo_unlink(file->path_lock); p_unlink(file->path_lock);
else else
return git__throw(GIT_EOSERR, "Failed to lock file"); return git__throw(GIT_EOSERR, "Failed to lock file");
} }
/* create path to the file buffer is required */ /* create path to the file buffer is required */
if (flags & GIT_FILEBUF_FORCE) { 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 { } else {
file->fd = gitfo_creat_locked(file->path_lock, 0644); file->fd = git_futils_creat_locked(file->path_lock, 0644);
} }
if (file->fd < 0) if (file->fd < 0)
return git__throw(GIT_EOSERR, "Failed to create lock"); 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; git_file source;
char buffer[2048]; char buffer[2048];
size_t read_bytes; size_t read_bytes;
source = gitfo_open(file->path_original, O_RDONLY); source = p_open(file->path_original, O_RDONLY);
if (source < 0) if (source < 0)
return git__throw(GIT_EOSERR, "Failed to lock file. Could not open %s", file->path_original); 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) { while ((read_bytes = p_read(source, buffer, 2048)) > 0) {
gitfo_write(file->fd, buffer, read_bytes); p_write(file->fd, buffer, read_bytes);
if (file->digest) if (file->digest)
git_hash_update(file->digest, buffer, read_bytes); git_hash_update(file->digest, buffer, read_bytes);
} }
gitfo_close(source); p_close(source);
} }
return GIT_SUCCESS; return GIT_SUCCESS;
...@@ -73,10 +73,10 @@ static int lock_file(git_filebuf *file, int flags) ...@@ -73,10 +73,10 @@ static int lock_file(git_filebuf *file, int flags)
void git_filebuf_cleanup(git_filebuf *file) void git_filebuf_cleanup(git_filebuf *file)
{ {
if (file->fd >= 0) 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) if (file->fd >= 0 && file->path_lock && git_futils_exists(file->path_lock) == GIT_SUCCESS)
gitfo_unlink(file->path_lock); p_unlink(file->path_lock);
if (file->digest) if (file->digest)
git_hash_free_ctx(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) ...@@ -102,7 +102,7 @@ static int write_normal(git_filebuf *file, const void *source, size_t len)
int result = 0; int result = 0;
if (len > 0) { if (len > 0) {
result = gitfo_write(file->fd, (void *)source, len); result = p_write(file->fd, (void *)source, len);
if (file->digest) if (file->digest)
git_hash_update(file->digest, source, len); git_hash_update(file->digest, source, len);
} }
...@@ -130,7 +130,7 @@ static int write_deflate(git_filebuf *file, const void *source, size_t 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; 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"); return git__throw(GIT_EOSERR, "Failed to write to file");
} while (zs->avail_out == 0); } while (zs->avail_out == 0);
...@@ -200,7 +200,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags) ...@@ -200,7 +200,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
char tmp_path[GIT_PATH_MAX]; char tmp_path[GIT_PATH_MAX];
/* Open the file as temporary for locking */ /* 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) { if (file->fd < 0) {
error = GIT_EOSERR; error = GIT_EOSERR;
goto cleanup; goto cleanup;
...@@ -283,10 +283,10 @@ int git_filebuf_commit(git_filebuf *file) ...@@ -283,10 +283,10 @@ int git_filebuf_commit(git_filebuf *file)
if ((error = flush_buffer(file)) < GIT_SUCCESS) if ((error = flush_buffer(file)) < GIT_SUCCESS)
goto cleanup; goto cleanup;
gitfo_close(file->fd); p_close(file->fd);
file->fd = -1; file->fd = -1;
error = gitfo_mv(file->path_lock, file->path_original); error = git_futils_mv_atomic(file->path_lock, file->path_original);
cleanup: cleanup:
git_filebuf_cleanup(file); git_filebuf_cleanup(file);
......
...@@ -9,110 +9,98 @@ ...@@ -9,110 +9,98 @@
#include "common.h" #include "common.h"
#include "map.h" #include "map.h"
#include "dir.h" #include "dir.h"
#include <fcntl.h> #include "posix.h"
#include <time.h> #include "path.h"
#ifdef GIT_WIN32 /**
#define GIT_PLATFORM_PATH_SEP '\\' * Filebuffer methods
#else *
#define GIT_PLATFORM_PATH_SEP '/' * Read whole files into an in-memory buffer for processing
#endif */
#define GIT_FBUFFER_INIT {NULL, 0}
#define S_IFGITLINK 0160000
#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
#ifdef GIT_WIN32
GIT_INLINE(int) link(const char *GIT_UNUSED(old), const char *GIT_UNUSED(new))
{
GIT_UNUSED_ARG(old)
GIT_UNUSED_ARG(new)
errno = ENOSYS;
return -1;
}
GIT_INLINE(int) git__mkdir(const char *path, int GIT_UNUSED(mode))
{
GIT_UNUSED_ARG(mode)
return mkdir(path);
}
extern int git__unlink(const char *path);
extern int git__mkstemp(char *template);
extern int git__fsync(int fd);
# ifndef GIT__WIN32_NO_HIDE_FILEOPS
# define unlink(p) git__unlink(p)
# define mkstemp(t) git__mkstemp(t)
# define mkdir(p,m) git__mkdir(p, m)
# define fsync(fd) git__fsync(fd)
# endif
#endif /* GIT_WIN32 */
#if !defined(O_BINARY)
#define O_BINARY 0
#endif
#define GITFO_BUF_INIT {NULL, 0}
typedef int git_file;
typedef struct { /* file io buffer */ typedef struct { /* file io buffer */
void *data; /* data bytes */ void *data; /* data bytes */
size_t len; /* data length */ size_t len; /* data length */
} gitfo_buf; } git_fbuffer;
extern int gitfo_exists(const char *path); extern int git_futils_readbuffer(git_fbuffer *obj, const char *path);
extern int gitfo_open(const char *path, int flags); extern void git_futils_freebuffer(git_fbuffer *obj);
extern int gitfo_creat(const char *path, int mode);
extern int gitfo_creat_force(const char *path, int mode); /**
extern int gitfo_creat_locked(const char *path, int mode); * File utils
extern int gitfo_creat_locked_force(const char *path, int mode); *
extern int gitfo_mktemp(char *path_out, const char *filename); * These are custom filesystem-related helper methods. They are
extern int gitfo_isdir(const char *path); * rather high level, and wrap the underlying POSIX methods
extern int gitfo_isfile(const char *path); *
extern int gitfo_mkdir_recurs(const char *path, int mode); * All these methods return GIT_SUCCESS on success,
extern int gitfo_mkdir_2file(const char *path); * or an error code on failure and an error message is set.
#define gitfo_close(fd) close(fd) */
extern int gitfo_read(git_file fd, void *buf, size_t cnt); /**
extern int gitfo_write(git_file fd, void *buf, size_t cnt); * Check if a file exists and can be accessed.
#define gitfo_lseek(f,n,w) lseek(f, n, w) */
extern git_off_t gitfo_size(git_file fd); extern int git_futils_exists(const char *path);
extern int gitfo_read_file(gitfo_buf *obj, const char *path); /**
extern void gitfo_free_buf(gitfo_buf *obj); * Create and open a file, while also
* creating all the folders in its path
/* Move (rename) a file; this operation is atomic */ */
extern int gitfo_mv(const char *from, const char *to); extern int git_futils_creat_withpath(const char *path, int mode);
/* Move a file (forced); this will create the destination /**
* path if it doesn't exist */ * Create an open a process-locked file
extern int gitfo_mv_force(const char *from, const char *to); */
extern int git_futils_creat_locked(const char *path, int mode);
#define gitfo_stat(p,b) stat(p, b)
#define gitfo_fstat(f,b) fstat(f, b) /**
* Create an open a process-locked file, while
#ifdef GIT_WIN32 * also creating all the folders in its path
# define gitfo_lstat(p,b) gitfo_lstat__w32(p,b) */
# define gitfo_readlink(a, b, c) gitfo_readlink__w32(a, b, c) extern int git_futils_creat_locked_withpath(const char *path, int mode);
extern int gitfo_lstat__w32(const char *file_name, struct stat *buf); /**
extern int gitfo_readlink__w32(const char *link, char *target, size_t target_len); * Check if the given path points to a directory
extern int gitfo_hide_directory__w32(const char *path); */
#else extern int git_futils_isdir(const char *path);
# define gitfo_lstat(p,b) lstat(p,b)
# define gitfo_readlink(a, b, c) readlink(a, b, c) /**
#endif * Check if the given path points to a regular file
*/
#define gitfo_unlink(p) unlink(p) extern int git_futils_isfile(const char *path);
#define gitfo_rmdir(p) rmdir(p)
#define gitfo_chdir(p) chdir(p) /**
#define gitfo_mkdir(p,m) mkdir(p, m) * Create a path recursively
*/
#define gitfo_mkstemp(t) mkstemp(t) extern int git_futils_mkdir_r(const char *path, int mode);
#define gitfo_fsync(fd) fsync(fd)
#define gitfo_chmod(p,m) chmod(p, m) /**
* Create all the folders required to contain
* the full path of a file
*/
extern int git_futils_mkpath2file(const char *path);
/**
* Create and open a temporary file with a `_git2_` suffix
*/
extern int git_futils_mktmp(char *path_out, const char *filename);
/**
* Atomically rename a file on the filesystem
*/
extern int git_futils_mv_atomic(const char *from, const char *to);
/**
* Move a file on the filesystem, create the
* destination path if it doesn't exist
*/
extern int git_futils_mv_withpath(const char *from, const char *to);
/**
* Get the filesize in bytes of a file
*/
extern git_off_t git_futils_filesize(git_file fd);
/** /**
* Read-only map all or part of a file into memory. * Read-only map all or part of a file into memory.
...@@ -129,7 +117,7 @@ extern int gitfo_mv_force(const char *from, const char *to); ...@@ -129,7 +117,7 @@ extern int gitfo_mv_force(const char *from, const char *to);
* - GIT_SUCCESS on success; * - GIT_SUCCESS on success;
* - GIT_EOSERR on an unspecified OS related error. * - GIT_EOSERR on an unspecified OS related error.
*/ */
extern int gitfo_map_ro( extern int git_futils_mmap_ro(
git_map *out, git_map *out,
git_file fd, git_file fd,
git_off_t begin, git_off_t begin,
...@@ -139,7 +127,7 @@ extern int gitfo_map_ro( ...@@ -139,7 +127,7 @@ extern int gitfo_map_ro(
* Release the memory associated with a previous memory mapping. * Release the memory associated with a previous memory mapping.
* @param map the mapping description previously configured. * @param map the mapping description previously configured.
*/ */
extern void gitfo_free_map(git_map *map); extern void git_futils_mmap_free(git_map *map);
/** /**
* Walk each directory entry, except '.' and '..', calling fn(state). * Walk each directory entry, except '.' and '..', calling fn(state).
...@@ -152,16 +140,15 @@ extern void gitfo_free_map(git_map *map); ...@@ -152,16 +140,15 @@ extern void gitfo_free_map(git_map *map);
* may modify the pathbuf, but only by appending new text. * may modify the pathbuf, but only by appending new text.
* @param state to pass to fn as the first arg. * @param state to pass to fn as the first arg.
*/ */
extern int gitfo_dirent( extern int git_futils_direach(
char *pathbuf, char *pathbuf,
size_t pathmax, size_t pathmax,
int (*fn)(void *, char *), int (*fn)(void *, char *),
void *state); void *state);
extern int gitfo_cmp_path(const char *name1, int len1, int isdir1, extern int git_futils_cmp_path(const char *name1, int len1, int isdir1,
const char *name2, int len2, int isdir2); const char *name2, int len2, int isdir2);
extern int gitfo_getcwd(char *buffer_out, size_t size);
/** /**
* Clean up a provided absolute or relative directory path. * Clean up a provided absolute or relative directory path.
...@@ -186,7 +173,7 @@ extern int gitfo_getcwd(char *buffer_out, size_t size); ...@@ -186,7 +173,7 @@ extern int gitfo_getcwd(char *buffer_out, size_t size);
* - GIT_SUCCESS on success; * - GIT_SUCCESS on success;
* - GIT_ERROR when the input path is invalid or escapes the current directory. * - GIT_ERROR when the input path is invalid or escapes the current directory.
*/ */
int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, const char *base_path); int git_futils_prettify_dir(char *buffer_out, size_t size, const char *path, const char *base_path);
/** /**
* Clean up a provided absolute or relative file path. * Clean up a provided absolute or relative file path.
...@@ -209,10 +196,8 @@ int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, con ...@@ -209,10 +196,8 @@ int gitfo_prettify_dir_path(char *buffer_out, size_t size, const char *path, con
* - GIT_SUCCESS on success; * - GIT_SUCCESS on success;
* - GIT_ERROR when the input path is invalid or escapes the current directory. * - GIT_ERROR when the input path is invalid or escapes the current directory.
*/ */
int gitfo_prettify_file_path(char *buffer_out, size_t size, const char *path, const char *base_path); int git_futils_prettyify_file(char *buffer_out, size_t size, const char *path, const char *base_path);
void gitfo_posixify_path(char *path);
int gitfo_retrieve_path_root_offset(const char *path); int git_futils_root_offset(const char *path);
#endif /* INCLUDE_fileops_h__ */ #endif /* INCLUDE_fileops_h__ */
...@@ -170,7 +170,7 @@ static int index_initialize(git_index **index_out, git_repository *owner, const ...@@ -170,7 +170,7 @@ static int index_initialize(git_index **index_out, git_repository *owner, const
git_vector_init(&index->entries, 32, index_cmp); git_vector_init(&index->entries, 32, index_cmp);
/* Check if index file is stored on disk already */ /* Check if index file is stored on disk already */
if (gitfo_exists(index->index_file_path) == 0) if (git_futils_exists(index->index_file_path) == 0)
index->on_disk = 1; index->on_disk = 1;
*index_out = index; *index_out = index;
...@@ -259,13 +259,13 @@ int git_index_read(git_index *index) ...@@ -259,13 +259,13 @@ int git_index_read(git_index *index)
assert(index->index_file_path); assert(index->index_file_path);
if (!index->on_disk || gitfo_exists(index->index_file_path) < 0) { if (!index->on_disk || git_futils_exists(index->index_file_path) < 0) {
git_index_clear(index); git_index_clear(index);
index->on_disk = 0; index->on_disk = 0;
return GIT_SUCCESS; return GIT_SUCCESS;
} }
if (gitfo_stat(index->index_file_path, &indexst) < 0) if (p_stat(index->index_file_path, &indexst) < 0)
return git__throw(GIT_EOSERR, "Failed to read index. %s does not exist or is corrupted", index->index_file_path); return git__throw(GIT_EOSERR, "Failed to read index. %s does not exist or is corrupted", index->index_file_path);
if (!S_ISREG(indexst.st_mode)) if (!S_ISREG(indexst.st_mode))
...@@ -273,9 +273,9 @@ int git_index_read(git_index *index) ...@@ -273,9 +273,9 @@ int git_index_read(git_index *index)
if (indexst.st_mtime != index->last_modified) { if (indexst.st_mtime != index->last_modified) {
gitfo_buf buffer; git_fbuffer buffer;
if ((error = gitfo_read_file(&buffer, index->index_file_path)) < GIT_SUCCESS) if ((error = git_futils_readbuffer(&buffer, index->index_file_path)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to read index"); return git__rethrow(error, "Failed to read index");
git_index_clear(index); git_index_clear(index);
...@@ -284,7 +284,7 @@ int git_index_read(git_index *index) ...@@ -284,7 +284,7 @@ int git_index_read(git_index *index)
if (error == GIT_SUCCESS) if (error == GIT_SUCCESS)
index->last_modified = indexst.st_mtime; index->last_modified = indexst.st_mtime;
gitfo_free_buf(&buffer); git_futils_freebuffer(&buffer);
} }
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
...@@ -311,7 +311,7 @@ int git_index_write(git_index *index) ...@@ -311,7 +311,7 @@ int git_index_write(git_index *index)
if ((error = git_filebuf_commit(&file)) < GIT_SUCCESS) if ((error = git_filebuf_commit(&file)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write index"); return git__rethrow(error, "Failed to write index");
if (gitfo_stat(index->index_file_path, &indexst) == 0) { if (p_stat(index->index_file_path, &indexst) == 0) {
index->last_modified = indexst.st_mtime; index->last_modified = indexst.st_mtime;
index->on_disk = 1; index->on_disk = 1;
} }
...@@ -409,9 +409,9 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char ...@@ -409,9 +409,9 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char
if (index->repository == NULL) if (index->repository == NULL)
return git__throw(GIT_EBAREINDEX, "Failed to initialize entry. Repository is bare"); return git__throw(GIT_EBAREINDEX, "Failed to initialize entry. Repository is bare");
git__joinpath(full_path, index->repository->path_workdir, rel_path); git_path_join(full_path, index->repository->path_workdir, rel_path);
if (gitfo_lstat(full_path, &st) < 0) if (p_lstat(full_path, &st) < 0)
return git__throw(GIT_EOSERR, "Failed to initialize entry. '%s' cannot be opened", full_path); return git__throw(GIT_EOSERR, "Failed to initialize entry. '%s' cannot be opened", full_path);
if (stage < 0 || stage > 3) if (stage < 0 || stage > 3)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "common.h" #include "common.h"
/* git__mmap() prot values */ /* p_mmap() prot values */
#define GIT_PROT_NONE 0x0 #define GIT_PROT_NONE 0x0
#define GIT_PROT_READ 0x1 #define GIT_PROT_READ 0x1
#define GIT_PROT_WRITE 0x2 #define GIT_PROT_WRITE 0x2
...@@ -25,7 +25,7 @@ typedef struct { /* memory mapped buffer */ ...@@ -25,7 +25,7 @@ typedef struct { /* memory mapped buffer */
#endif #endif
} git_map; } git_map;
extern int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset); extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset);
extern int git__munmap(git_map *map); extern int p_munmap(git_map *map);
#endif /* INCLUDE_map_h__ */ #endif /* INCLUDE_map_h__ */
...@@ -323,15 +323,15 @@ static int load_alternates(git_odb *odb, const char *objects_dir) ...@@ -323,15 +323,15 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
char alternates_path[GIT_PATH_MAX]; char alternates_path[GIT_PATH_MAX];
char *buffer, *alternate; char *buffer, *alternate;
gitfo_buf alternates_buf = GITFO_BUF_INIT; git_fbuffer alternates_buf = GIT_FBUFFER_INIT;
int error; int error;
git__joinpath(alternates_path, objects_dir, GIT_ALTERNATES_FILE); git_path_join(alternates_path, objects_dir, GIT_ALTERNATES_FILE);
if (gitfo_exists(alternates_path) < GIT_SUCCESS) if (git_futils_exists(alternates_path) < GIT_SUCCESS)
return GIT_SUCCESS; return GIT_SUCCESS;
if (gitfo_read_file(&alternates_buf, alternates_path) < GIT_SUCCESS) if (git_futils_readbuffer(&alternates_buf, alternates_path) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to add backend. Can't read alternates"); return git__throw(GIT_EOSERR, "Failed to add backend. Can't read alternates");
buffer = (char *)alternates_buf.data; buffer = (char *)alternates_buf.data;
...@@ -346,7 +346,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir) ...@@ -346,7 +346,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
/* relative path: build based on the current `objects` folder */ /* relative path: build based on the current `objects` folder */
if (*alternate == '.') { if (*alternate == '.') {
git__joinpath(full_path, objects_dir, alternate); git_path_join(full_path, objects_dir, alternate);
alternate = full_path; alternate = full_path;
} }
...@@ -354,7 +354,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir) ...@@ -354,7 +354,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir)
break; break;
} }
gitfo_free_buf(&alternates_buf); git_futils_freebuffer(&alternates_buf);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to load alternates"); return git__rethrow(error, "Failed to load alternates");
return error; return error;
......
...@@ -97,7 +97,7 @@ static size_t object_file_name(char *name, size_t n, char *dir, const git_oid *i ...@@ -97,7 +97,7 @@ static size_t object_file_name(char *name, size_t n, char *dir, const git_oid *i
} }
static size_t get_binary_object_header(obj_hdr *hdr, gitfo_buf *obj) static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj)
{ {
unsigned char c; unsigned char c;
unsigned char *data = obj->data; unsigned char *data = obj->data;
...@@ -199,7 +199,7 @@ static void set_stream_output(z_stream *s, void *out, size_t len) ...@@ -199,7 +199,7 @@ static void set_stream_output(z_stream *s, void *out, size_t len)
} }
static int start_inflate(z_stream *s, gitfo_buf *obj, void *out, size_t len) static int start_inflate(z_stream *s, git_fbuffer *obj, void *out, size_t len)
{ {
int status; int status;
...@@ -309,7 +309,7 @@ static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr) ...@@ -309,7 +309,7 @@ static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr)
* of loose object data into packs. This format is no longer used, but * of loose object data into packs. This format is no longer used, but
* we must still read it. * we must still read it.
*/ */
static int inflate_packlike_loose_disk_obj(git_rawobj *out, gitfo_buf *obj) static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
{ {
unsigned char *in, *buf; unsigned char *in, *buf;
obj_hdr hdr; obj_hdr hdr;
...@@ -347,7 +347,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, gitfo_buf *obj) ...@@ -347,7 +347,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, gitfo_buf *obj)
return GIT_SUCCESS; return GIT_SUCCESS;
} }
static int inflate_disk_obj(git_rawobj *out, gitfo_buf *obj) static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
{ {
unsigned char head[64], *buf; unsigned char head[64], *buf;
z_stream zs; z_stream zs;
...@@ -405,7 +405,7 @@ static int inflate_disk_obj(git_rawobj *out, gitfo_buf *obj) ...@@ -405,7 +405,7 @@ static int inflate_disk_obj(git_rawobj *out, gitfo_buf *obj)
static int read_loose(git_rawobj *out, const char *loc) static int read_loose(git_rawobj *out, const char *loc)
{ {
int error; int error;
gitfo_buf obj = GITFO_BUF_INIT; git_fbuffer obj = GIT_FBUFFER_INIT;
assert(out && loc); assert(out && loc);
...@@ -413,11 +413,11 @@ static int read_loose(git_rawobj *out, const char *loc) ...@@ -413,11 +413,11 @@ static int read_loose(git_rawobj *out, const char *loc)
out->len = 0; out->len = 0;
out->type = GIT_OBJ_BAD; out->type = GIT_OBJ_BAD;
if (gitfo_read_file(&obj, loc) < 0) if (git_futils_readbuffer(&obj, loc) < 0)
return git__throw(GIT_ENOTFOUND, "Failed to read loose object. File not found"); return git__throw(GIT_ENOTFOUND, "Failed to read loose object. File not found");
error = inflate_disk_obj(out, &obj); error = inflate_disk_obj(out, &obj);
gitfo_free_buf(&obj); git_futils_freebuffer(&obj);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read loose object"); return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read loose object");
} }
...@@ -434,7 +434,7 @@ static int read_header_loose(git_rawobj *out, const char *loc) ...@@ -434,7 +434,7 @@ static int read_header_loose(git_rawobj *out, const char *loc)
out->data = NULL; out->data = NULL;
if ((fd = gitfo_open(loc, O_RDONLY)) < 0) if ((fd = p_open(loc, O_RDONLY)) < 0)
return git__throw(GIT_ENOTFOUND, "Failed to read loose object header. File not found"); return git__throw(GIT_ENOTFOUND, "Failed to read loose object header. File not found");
init_stream(&zs, inflated_buffer, sizeof(inflated_buffer)); init_stream(&zs, inflated_buffer, sizeof(inflated_buffer));
...@@ -466,7 +466,7 @@ static int read_header_loose(git_rawobj *out, const char *loc) ...@@ -466,7 +466,7 @@ static int read_header_loose(git_rawobj *out, const char *loc)
cleanup: cleanup:
finish_inflate(&zs); finish_inflate(&zs);
gitfo_close(fd); p_close(fd);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__throw(error, "Failed to read loose object header. Header is corrupted"); return git__throw(error, "Failed to read loose object header. Header is corrupted");
...@@ -477,7 +477,7 @@ cleanup: ...@@ -477,7 +477,7 @@ cleanup:
static int locate_object(char *object_location, loose_backend *backend, const git_oid *oid) static int locate_object(char *object_location, loose_backend *backend, const git_oid *oid)
{ {
object_file_name(object_location, GIT_PATH_MAX, backend->objects_dir, oid); object_file_name(object_location, GIT_PATH_MAX, backend->objects_dir, oid);
return gitfo_exists(object_location); return git_futils_exists(object_location);
} }
/* Explore an entry of a directory and see if it matches a short oid */ /* Explore an entry of a directory and see if it matches a short oid */
...@@ -490,7 +490,7 @@ int fn_locate_object_short_oid(void *state, char *pathbuf) { ...@@ -490,7 +490,7 @@ int fn_locate_object_short_oid(void *state, char *pathbuf) {
return GIT_SUCCESS; return GIT_SUCCESS;
} }
if (!gitfo_exists(pathbuf) && gitfo_isdir(pathbuf)) { if (!git_futils_exists(pathbuf) && git_futils_isdir(pathbuf)) {
/* We are already in the directory matching the 2 first hex characters, /* We are already in the directory matching the 2 first hex characters,
* compare the first ncmp characters of the oids */ * compare the first ncmp characters of the oids */
if (!memcmp(sstate->short_oid + 2, if (!memcmp(sstate->short_oid + 2,
...@@ -534,14 +534,14 @@ static int locate_object_short_oid(char *object_location, git_oid *res_oid, loos ...@@ -534,14 +534,14 @@ static int locate_object_short_oid(char *object_location, git_oid *res_oid, loos
sprintf(object_location+dir_len, "%.2s/", state.short_oid); sprintf(object_location+dir_len, "%.2s/", state.short_oid);
/* Check that directory exists */ /* Check that directory exists */
if (gitfo_exists(object_location) || gitfo_isdir(object_location)) if (git_futils_exists(object_location) || git_futils_isdir(object_location))
return git__throw(GIT_ENOTFOUND, "Failed to locate object from short oid. Object not found"); return git__throw(GIT_ENOTFOUND, "Failed to locate object from short oid. Object not found");
state.dir_len = dir_len+3; state.dir_len = dir_len+3;
state.short_oid_len = len; state.short_oid_len = len;
state.found = 0; state.found = 0;
/* Explore directory to find a unique object matching short_oid */ /* Explore directory to find a unique object matching short_oid */
error = gitfo_dirent(object_location, GIT_PATH_MAX, fn_locate_object_short_oid, &state); error = git_futils_direach(object_location, GIT_PATH_MAX, fn_locate_object_short_oid, &state);
if (error) { if (error) {
return git__rethrow(error, "Failed to locate object from short oid"); return git__rethrow(error, "Failed to locate object from short oid");
} }
...@@ -684,7 +684,7 @@ int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream) ...@@ -684,7 +684,7 @@ int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
if (object_file_name(final_path, sizeof(final_path), backend->objects_dir, oid)) if (object_file_name(final_path, sizeof(final_path), backend->objects_dir, oid))
return GIT_ENOMEM; return GIT_ENOMEM;
if ((error = gitfo_mkdir_2file(final_path)) < GIT_SUCCESS) if ((error = git_futils_mkpath2file(final_path)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write loose backend"); return git__rethrow(error, "Failed to write loose backend");
stream->finished = 1; stream->finished = 1;
...@@ -749,7 +749,7 @@ int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend ...@@ -749,7 +749,7 @@ int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend
stream->stream.free = &loose_backend__stream_free; stream->stream.free = &loose_backend__stream_free;
stream->stream.mode = GIT_STREAM_WRONLY; stream->stream.mode = GIT_STREAM_WRONLY;
git__joinpath(tmp_path, backend->objects_dir, "tmp_object"); git_path_join(tmp_path, backend->objects_dir, "tmp_object");
error = git_filebuf_open(&stream->fbuf, tmp_path, error = git_filebuf_open(&stream->fbuf, tmp_path,
GIT_FILEBUF_HASH_CONTENTS | GIT_FILEBUF_HASH_CONTENTS |
......
...@@ -359,7 +359,7 @@ void pack_window_free_all(struct pack_backend *backend, struct pack_file *p) ...@@ -359,7 +359,7 @@ void pack_window_free_all(struct pack_backend *backend, struct pack_file *p)
backend->mapped -= w->window_map.len; backend->mapped -= w->window_map.len;
backend->open_windows--; backend->open_windows--;
gitfo_free_map(&w->window_map); git_futils_mmap_free(&w->window_map);
p->windows = w->next; p->windows = w->next;
free(w); free(w);
...@@ -416,14 +416,14 @@ static int pack_window_close_lru( ...@@ -416,14 +416,14 @@ static int pack_window_close_lru(
if (lru_p) { if (lru_p) {
backend->mapped -= lru_w->window_map.len; backend->mapped -= lru_w->window_map.len;
gitfo_free_map(&lru_w->window_map); git_futils_mmap_free(&lru_w->window_map);
if (lru_l) if (lru_l)
lru_l->next = lru_w->next; lru_l->next = lru_w->next;
else { else {
lru_p->windows = lru_w->next; lru_p->windows = lru_w->next;
if (!lru_p->windows && lru_p->pack_fd != keep_fd) { if (!lru_p->windows && lru_p->pack_fd != keep_fd) {
gitfo_close(lru_p->pack_fd); p_close(lru_p->pack_fd);
lru_p->pack_fd = -1; lru_p->pack_fd = -1;
} }
} }
...@@ -491,7 +491,7 @@ static unsigned char *pack_window_open( ...@@ -491,7 +491,7 @@ static unsigned char *pack_window_open(
while (backend->mapped_limit < backend->mapped && while (backend->mapped_limit < backend->mapped &&
pack_window_close_lru(backend, p, p->pack_fd) == GIT_SUCCESS) {} pack_window_close_lru(backend, p, p->pack_fd) == GIT_SUCCESS) {}
if (gitfo_map_ro(&win->window_map, p->pack_fd, if (git_futils_mmap_ro(&win->window_map, p->pack_fd,
win->offset, len) < GIT_SUCCESS) win->offset, len) < GIT_SUCCESS)
return NULL; return NULL;
...@@ -539,7 +539,7 @@ static unsigned char *pack_window_open( ...@@ -539,7 +539,7 @@ static unsigned char *pack_window_open(
static void pack_index_free(struct pack_file *p) static void pack_index_free(struct pack_file *p)
{ {
if (p->index_map.data) { if (p->index_map.data) {
gitfo_free_map(&p->index_map); git_futils_mmap_free(&p->index_map);
p->index_map.data = NULL; p->index_map.data = NULL;
} }
} }
...@@ -555,15 +555,15 @@ static int pack_index_check(const char *path, struct pack_file *p) ...@@ -555,15 +555,15 @@ static int pack_index_check(const char *path, struct pack_file *p)
struct stat st; struct stat st;
/* TODO: properly open the file without access time */ /* TODO: properly open the file without access time */
git_file fd = gitfo_open(path, O_RDONLY /*| O_NOATIME */); git_file fd = p_open(path, O_RDONLY /*| O_NOATIME */);
int error; int error;
if (fd < 0) if (fd < 0)
return git__throw(GIT_EOSERR, "Failed to check index. File missing or corrupted"); return git__throw(GIT_EOSERR, "Failed to check index. File missing or corrupted");
if (gitfo_fstat(fd, &st) < GIT_SUCCESS) { if (p_fstat(fd, &st) < GIT_SUCCESS) {
gitfo_close(fd); p_close(fd);
return git__throw(GIT_EOSERR, "Failed to check index. File appears to be corrupted"); return git__throw(GIT_EOSERR, "Failed to check index. File appears to be corrupted");
} }
...@@ -573,12 +573,12 @@ static int pack_index_check(const char *path, struct pack_file *p) ...@@ -573,12 +573,12 @@ static int pack_index_check(const char *path, struct pack_file *p)
idx_size = (size_t)st.st_size; idx_size = (size_t)st.st_size;
if (idx_size < 4 * 256 + 20 + 20) { if (idx_size < 4 * 256 + 20 + 20) {
gitfo_close(fd); p_close(fd);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted"); return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted");
} }
error = gitfo_map_ro(&p->index_map, fd, 0, idx_size); error = git_futils_mmap_ro(&p->index_map, fd, 0, idx_size);
gitfo_close(fd); p_close(fd);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to check index"); return git__rethrow(error, "Failed to check index");
...@@ -589,7 +589,7 @@ static int pack_index_check(const char *path, struct pack_file *p) ...@@ -589,7 +589,7 @@ static int pack_index_check(const char *path, struct pack_file *p)
version = ntohl(hdr->idx_version); version = ntohl(hdr->idx_version);
if (version < 2 || version > 2) { if (version < 2 || version > 2) {
gitfo_free_map(&p->index_map); git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Unsupported index version"); return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Unsupported index version");
} }
...@@ -605,7 +605,7 @@ static int pack_index_check(const char *path, struct pack_file *p) ...@@ -605,7 +605,7 @@ static int pack_index_check(const char *path, struct pack_file *p)
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
uint32_t n = ntohl(index[i]); uint32_t n = ntohl(index[i]);
if (n < nr) { if (n < nr) {
gitfo_free_map(&p->index_map); git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Index is non-monotonic"); return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Index is non-monotonic");
} }
nr = n; nr = n;
...@@ -620,7 +620,7 @@ static int pack_index_check(const char *path, struct pack_file *p) ...@@ -620,7 +620,7 @@ static int pack_index_check(const char *path, struct pack_file *p)
* - 20-byte SHA1 file checksum * - 20-byte SHA1 file checksum
*/ */
if (idx_size != 4*256 + nr * 24 + 20 + 20) { if (idx_size != 4*256 + nr * 24 + 20 + 20) {
gitfo_free_map(&p->index_map); git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted"); return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted");
} }
} else if (version == 2) { } else if (version == 2) {
...@@ -644,14 +644,14 @@ static int pack_index_check(const char *path, struct pack_file *p) ...@@ -644,14 +644,14 @@ static int pack_index_check(const char *path, struct pack_file *p)
max_size += (nr - 1)*8; max_size += (nr - 1)*8;
if (idx_size < min_size || idx_size > max_size) { if (idx_size < min_size || idx_size > max_size) {
gitfo_free_map(&p->index_map); git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Wrong index size"); return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Wrong index size");
} }
/* Make sure that off_t is big enough to access the whole pack... /* Make sure that off_t is big enough to access the whole pack...
* Is this an issue in libgit2? It shouldn't. */ * Is this an issue in libgit2? It shouldn't. */
if (idx_size != min_size && (sizeof(off_t) <= 4)) { if (idx_size != min_size && (sizeof(off_t) <= 4)) {
gitfo_free_map(&p->index_map); git_futils_mmap_free(&p->index_map);
return git__throw(GIT_EOSERR, "Failed to check index. off_t not big enough to access the whole pack"); return git__throw(GIT_EOSERR, "Failed to check index. off_t not big enough to access the whole pack");
} }
} }
...@@ -738,7 +738,7 @@ static void packfile_free(struct pack_backend *backend, struct pack_file *p) ...@@ -738,7 +738,7 @@ static void packfile_free(struct pack_backend *backend, struct pack_file *p)
pack_window_free_all(backend, p); pack_window_free_all(backend, p);
if (p->pack_fd != -1) if (p->pack_fd != -1)
gitfo_close(p->pack_fd); p_close(p->pack_fd);
pack_index_free(p); pack_index_free(p);
...@@ -757,8 +757,8 @@ static int packfile_open(struct pack_file *p) ...@@ -757,8 +757,8 @@ static int packfile_open(struct pack_file *p)
return git__throw(GIT_ENOTFOUND, "Failed to open packfile. File not found"); return git__throw(GIT_ENOTFOUND, "Failed to open packfile. File not found");
/* TODO: open with noatime */ /* TODO: open with noatime */
p->pack_fd = gitfo_open(p->pack_name, O_RDONLY); p->pack_fd = p_open(p->pack_name, O_RDONLY);
if (p->pack_fd < 0 || gitfo_fstat(p->pack_fd, &st) < GIT_SUCCESS) if (p->pack_fd < 0 || p_fstat(p->pack_fd, &st) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to open packfile. File appears to be corrupted"); return git__throw(GIT_EOSERR, "Failed to open packfile. File appears to be corrupted");
/* If we created the struct before we had the pack we lack size. */ /* If we created the struct before we had the pack we lack size. */
...@@ -783,7 +783,7 @@ static int packfile_open(struct pack_file *p) ...@@ -783,7 +783,7 @@ static int packfile_open(struct pack_file *p)
#endif #endif
/* Verify we recognize this pack file format. */ /* Verify we recognize this pack file format. */
if (gitfo_read(p->pack_fd, &hdr, sizeof(hdr)) < GIT_SUCCESS) if (p_read(p->pack_fd, &hdr, sizeof(hdr)) < GIT_SUCCESS)
goto cleanup; goto cleanup;
if (hdr.hdr_signature != htonl(PACK_SIGNATURE)) if (hdr.hdr_signature != htonl(PACK_SIGNATURE))
...@@ -796,10 +796,10 @@ static int packfile_open(struct pack_file *p) ...@@ -796,10 +796,10 @@ static int packfile_open(struct pack_file *p)
if (p->num_objects != ntohl(hdr.hdr_entries)) if (p->num_objects != ntohl(hdr.hdr_entries))
goto cleanup; goto cleanup;
if (gitfo_lseek(p->pack_fd, p->pack_size - GIT_OID_RAWSZ, SEEK_SET) == -1) if (p_lseek(p->pack_fd, p->pack_size - GIT_OID_RAWSZ, SEEK_SET) == -1)
goto cleanup; goto cleanup;
if (gitfo_read(p->pack_fd, sha1.id, GIT_OID_RAWSZ) < GIT_SUCCESS) if (p_read(p->pack_fd, sha1.id, GIT_OID_RAWSZ) < GIT_SUCCESS)
goto cleanup; goto cleanup;
idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40; idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;
...@@ -810,7 +810,7 @@ static int packfile_open(struct pack_file *p) ...@@ -810,7 +810,7 @@ static int packfile_open(struct pack_file *p)
return GIT_SUCCESS; return GIT_SUCCESS;
cleanup: cleanup:
gitfo_close(p->pack_fd); p_close(p->pack_fd);
p->pack_fd = -1; p->pack_fd = -1;
return git__throw(GIT_EPACKCORRUPTED, "Failed to packfile. Pack is corrupted"); return git__throw(GIT_EPACKCORRUPTED, "Failed to packfile. Pack is corrupted");
} }
...@@ -838,11 +838,11 @@ static int packfile_check(struct pack_file **pack_out, const char *path) ...@@ -838,11 +838,11 @@ static int packfile_check(struct pack_file **pack_out, const char *path)
memcpy(p->pack_name, path, path_len); memcpy(p->pack_name, path, path_len);
strcpy(p->pack_name + path_len, ".keep"); strcpy(p->pack_name + path_len, ".keep");
if (gitfo_exists(p->pack_name) == GIT_SUCCESS) if (git_futils_exists(p->pack_name) == GIT_SUCCESS)
p->pack_keep = 1; p->pack_keep = 1;
strcpy(p->pack_name + path_len, ".pack"); strcpy(p->pack_name + path_len, ".pack");
if (gitfo_stat(p->pack_name, &st) < GIT_SUCCESS || !S_ISREG(st.st_mode)) { if (p_stat(p->pack_name, &st) < GIT_SUCCESS || !S_ISREG(st.st_mode)) {
free(p); free(p);
return git__throw(GIT_ENOTFOUND, "Failed to check packfile. File not found"); return git__throw(GIT_ENOTFOUND, "Failed to check packfile. File not found");
} }
...@@ -899,7 +899,7 @@ static int packfile_refresh_all(struct pack_backend *backend) ...@@ -899,7 +899,7 @@ static int packfile_refresh_all(struct pack_backend *backend)
if (backend->pack_folder == NULL) if (backend->pack_folder == NULL)
return GIT_SUCCESS; return GIT_SUCCESS;
if (gitfo_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode)) if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
return git__throw(GIT_ENOTFOUND, "Failed to refresh packfiles. Backend not found"); return git__throw(GIT_ENOTFOUND, "Failed to refresh packfiles. Backend not found");
if (st.st_mtime != backend->pack_folder_mtime) { if (st.st_mtime != backend->pack_folder_mtime) {
...@@ -907,7 +907,7 @@ static int packfile_refresh_all(struct pack_backend *backend) ...@@ -907,7 +907,7 @@ static int packfile_refresh_all(struct pack_backend *backend)
strcpy(path, backend->pack_folder); strcpy(path, backend->pack_folder);
/* reload all packs */ /* reload all packs */
error = gitfo_dirent(path, GIT_PATH_MAX, packfile_load__cb, (void *)backend); error = git_futils_direach(path, GIT_PATH_MAX, packfile_load__cb, (void *)backend);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to refresh packfiles"); return git__rethrow(error, "Failed to refresh packfiles");
...@@ -1549,8 +1549,8 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir) ...@@ -1549,8 +1549,8 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
backend->window_size = DEFAULT_WINDOW_SIZE; backend->window_size = DEFAULT_WINDOW_SIZE;
backend->mapped_limit = DEFAULT_MAPPED_LIMIT; backend->mapped_limit = DEFAULT_MAPPED_LIMIT;
git__joinpath(path, objects_dir, "pack"); git_path_join(path, objects_dir, "pack");
if (gitfo_isdir(path) == GIT_SUCCESS) { if (git_futils_isdir(path) == GIT_SUCCESS) {
backend->pack_folder = git__strdup(path); backend->pack_folder = git__strdup(path);
backend->pack_folder_mtime = 0; backend->pack_folder_mtime = 0;
......
#include "common.h"
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
/*
* Based on the Android implementation, BSD licensed.
* Check http://android.git.kernel.org/
*/
int git_path_basename_r(char *buffer, size_t bufflen, const char *path)
{
const char *endp, *startp;
int len, result;
/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
startp = ".";
len = 1;
goto Exit;
}
/* Strip trailing slashes */
endp = path + strlen(path) - 1;
while (endp > path && *endp == '/')
endp--;
/* All slashes becomes "/" */
if (endp == path && *endp == '/') {
startp = "/";
len = 1;
goto Exit;
}
/* Find the start of the base */
startp = endp;
while (startp > path && *(startp - 1) != '/')
startp--;
len = endp - startp +1;
Exit:
result = len;
if (buffer == NULL) {
return result;
}
if (len > (int)bufflen-1) {
len = (int)bufflen-1;
result = GIT_ENOMEM;
}
if (len >= 0) {
memmove(buffer, startp, len);
buffer[len] = 0;
}
return result;
}
/*
* Based on the Android implementation, BSD licensed.
* Check http://android.git.kernel.org/
*/
int git_path_dirname_r(char *buffer, size_t bufflen, const char *path)
{
const char *endp;
int result, len;
/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
path = ".";
len = 1;
goto Exit;
}
/* Strip trailing slashes */
endp = path + strlen(path) - 1;
while (endp > path && *endp == '/')
endp--;
/* Find the start of the dir */
while (endp > path && *endp != '/')
endp--;
/* Either the dir is "/" or there are no slashes */
if (endp == path) {
path = (*endp == '/') ? "/" : ".";
len = 1;
goto Exit;
}
do {
endp--;
} while (endp > path && *endp == '/');
len = endp - path +1;
Exit:
result = len;
if (len+1 > GIT_PATH_MAX) {
return GIT_ENOMEM;
}
if (buffer == NULL)
return result;
if (len > (int)bufflen-1) {
len = (int)bufflen-1;
result = GIT_ENOMEM;
}
if (len >= 0) {
memmove(buffer, path, len);
buffer[len] = 0;
}
return result;
}
char *git_path_dirname(const char *path)
{
char *dname = NULL;
int len;
len = (path ? strlen(path) : 0) + 2;
dname = (char *)git__malloc(len);
if (dname == NULL)
return NULL;
if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) {
free(dname);
return NULL;
}
return dname;
}
char *git_path_basename(const char *path)
{
char *bname = NULL;
int len;
len = (path ? strlen(path) : 0) + 2;
bname = (char *)git__malloc(len);
if (bname == NULL)
return NULL;
if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) {
free(bname);
return NULL;
}
return bname;
}
const char *git_path_topdir(const char *path)
{
size_t len;
int i;
assert(path);
len = strlen(path);
if (!len || path[len - 1] != '/')
return NULL;
for (i = len - 2; i >= 0; --i)
if (path[i] == '/')
break;
return &path[i + 1];
}
void git_path_join_n(char *buffer_out, int count, ...)
{
va_list ap;
int i;
char *buffer_start = buffer_out;
va_start(ap, count);
for (i = 0; i < count; ++i) {
const char *path;
int len;
path = va_arg(ap, const char *);
assert((i == 0) || path != buffer_start);
if (i > 0 && *path == '/' && buffer_out > buffer_start && buffer_out[-1] == '/')
path++;
if (!*path)
continue;
len = strlen(path);
memmove(buffer_out, path, len);
buffer_out = buffer_out + len;
if (i < count - 1 && buffer_out[-1] != '/')
*buffer_out++ = '/';
}
va_end(ap);
*buffer_out = '\0';
}
/*
* posix.h - Path management methods
*/
#ifndef INCLUDE_path_h__
#define INCLUDE_path_h__
#include "common.h"
/*
* The dirname() function shall take a pointer to a character string
* that contains a pathname, and return a pointer to a string that is a
* pathname of the parent directory of that file. Trailing '/' characters
* in the path are not counted as part of the path.
*
* If path does not contain a '/', then dirname() shall return a pointer to
* the string ".". If path is a null pointer or points to an empty string,
* dirname() shall return a pointer to the string "." .
*
* The `git_path_dirname` implementation is thread safe. The returned
* string must be manually free'd.
*
* The `git_path_dirname_r` implementation expects a string allocated
* by the user with big enough size.
*/
extern char *git_path_dirname(const char *path);
extern int git_path_dirname_r(char *buffer, size_t bufflen, const char *path);
/*
* This function returns the basename of the file, which is the last
* part of its full name given by fname, with the drive letter and
* leading directories stripped off. For example, the basename of
* c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
*
* Trailing slashes and backslashes are significant: the basename of
* c:/foo/bar/ is an empty string after the rightmost slash.
*
* The `git_path_basename` implementation is thread safe. The returned
* string must be manually free'd.
*
* The `git_path_basename_r` implementation expects a string allocated
* by the user with big enough size.
*/
extern char *git_path_basename(const char *path);
extern int git_path_basename_r(char *buffer, size_t bufflen, const char *path);
extern const char *git_path_topdir(const char *path);
/**
* Join two paths together. Takes care of properly fixing the
* middle slashes and everything
*
* The paths are joined together into buffer_out; this is expected
* to be an user allocated buffer of `GIT_PATH_MAX` size
*/
extern void git_path_join_n(char *buffer_out, int npath, ...);
GIT_INLINE(void) git_path_join(char *buffer_out, const char *path_a, const char *path_b)
{
git_path_join_n(buffer_out, 2, path_a, path_b);
}
#ifdef GIT_WIN32
GIT_INLINE(void) git_path_mkposix(char *path)
{
while (*path) {
if (*path == '\\')
*path = '/';
path++;
}
}
#else
# define git_path_mkposix(p) /* blank */
#endif
#endif
#include "common.h"
#include "posix.h"
#include "path.h"
#include <stdio.h>
#include <ctype.h>
int p_open(const char *path, int flags)
{
return open(path, flags | O_BINARY);
}
int p_creat(const char *path, int mode)
{
return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
}
int p_read(git_file fd, void *buf, size_t cnt)
{
char *b = buf;
while (cnt) {
ssize_t r = read(fd, b, cnt);
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
return GIT_EOSERR;
}
if (!r)
break;
cnt -= r;
b += r;
}
return (int)(b - (char *)buf);
}
int p_write(git_file fd, void *buf, size_t cnt)
{
char *b = buf;
while (cnt) {
ssize_t r = write(fd, b, cnt);
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
return GIT_EOSERR;
}
if (!r) {
errno = EPIPE;
return GIT_EOSERR;
}
cnt -= r;
b += r;
}
return GIT_SUCCESS;
}
int p_getcwd(char *buffer_out, size_t size)
{
char *cwd_buffer;
assert(buffer_out && size > 0);
#ifdef GIT_WIN32
cwd_buffer = _getcwd(buffer_out, size);
#else
cwd_buffer = getcwd(buffer_out, size);
#endif
if (cwd_buffer == NULL)
return git__throw(GIT_EOSERR, "Failed to retrieve current working directory");
git_path_mkposix(buffer_out);
git_path_join(buffer_out, buffer_out, ""); //Ensure the path ends with a trailing slash
return GIT_SUCCESS;
}
/*
* posix.h - OS agnostic POSIX calls
*/
#ifndef INCLUDE_posix_h__
#define INCLUDE_posix_h__
#include "common.h"
#include <fcntl.h>
#include <time.h>
#ifdef GIT_WIN32
# include "win32/posix.h"
#else
# include "unix/posix.h"
#endif
#define S_IFGITLINK 0160000
#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
#if !defined(O_BINARY)
#define O_BINARY 0
#endif
typedef int git_file;
/**
* Standard POSIX Methods
*
* All the methods starting with the `p_` prefix are
* direct ports of the standard POSIX methods.
*
* Some of the methods are slightly wrapped to provide
* saner defaults. Some of these methods are emulated
* in Windows platforns.
*
* Use your manpages to check the docs on these.
* Straightforward
*/
extern int p_open(const char *path, int flags);
extern int p_creat(const char *path, int mode);
extern int p_read(git_file fd, void *buf, size_t cnt);
extern int p_write(git_file fd, void *buf, size_t cnt);
extern int p_getcwd(char *buffer_out, size_t size);
#define p_lseek(f,n,w) lseek(f, n, w)
#define p_stat(p,b) stat(p, b)
#define p_fstat(f,b) fstat(f, b)
#define p_chdir(p) chdir(p)
#define p_rmdir(p) rmdir(p)
#define p_chmod(p,m) chmod(p, m)
#define p_close(fd) close(fd)
#endif
...@@ -170,7 +170,7 @@ static int retreive_tag_reference(git_reference **tag_reference_out, char *ref_n ...@@ -170,7 +170,7 @@ static int retreive_tag_reference(git_reference **tag_reference_out, char *ref_n
git_reference *tag_ref; git_reference *tag_ref;
int error; int error;
git__joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name); git_path_join(ref_name_out, GIT_REFS_TAGS_DIR, tag_name);
error = git_reference_lookup(&tag_ref, repo, ref_name_out); error = git_reference_lookup(&tag_ref, repo, ref_name_out);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to retrieve tag reference"); return git__rethrow(error, "Failed to retrieve tag reference");
......
...@@ -56,7 +56,7 @@ int entry_sort_cmp(const void *a, const void *b) ...@@ -56,7 +56,7 @@ int entry_sort_cmp(const void *a, const void *b)
const git_tree_entry *entry_a = *(const git_tree_entry **)(a); const git_tree_entry *entry_a = *(const git_tree_entry **)(a);
const git_tree_entry *entry_b = *(const git_tree_entry **)(b); const git_tree_entry *entry_b = *(const git_tree_entry **)(b);
return gitfo_cmp_path(entry_a->filename, strlen(entry_a->filename), return git_futils_cmp_path(entry_a->filename, strlen(entry_a->filename),
entry_a->attr & 040000, entry_a->attr & 040000,
entry_b->filename, strlen(entry_b->filename), entry_b->filename, strlen(entry_b->filename),
entry_b->attr & 040000); entry_b->attr & 040000);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <errno.h> #include <errno.h>
int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
{ {
int mprot = 0; int mprot = 0;
int mflag = 0; int mflag = 0;
...@@ -48,7 +48,7 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t o ...@@ -48,7 +48,7 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t o
return GIT_SUCCESS; return GIT_SUCCESS;
} }
int git__munmap(git_map *map) int p_munmap(git_map *map)
{ {
assert(map != NULL); assert(map != NULL);
......
#ifndef INCLUDE_posix__w32_h__
#define INCLUDE_posix__w32_h__
#include "common.h"
#define p_lstat(p,b) lstat(p,b)
#define p_readlink(a, b, c) readlink(a, b, c)
#define p_link(o,n) link(o, n)
#define p_unlink(p) unlink(p)
#define p_mkdir(p,m) mkdir(p, m)
#define p_fsync(fd) fsync(fd)
#define p_realpath(p, r) realpath(p, r)
#endif
#define GIT__NO_HIDE_MALLOC
#include <git2.h> #include <git2.h>
#include "common.h" #include "common.h"
#include <stdarg.h> #include <stdarg.h>
...@@ -146,205 +145,6 @@ int git__suffixcmp(const char *str, const char *suffix) ...@@ -146,205 +145,6 @@ int git__suffixcmp(const char *str, const char *suffix)
return strcmp(str + (a - b), suffix); return strcmp(str + (a - b), suffix);
} }
/*
* Based on the Android implementation, BSD licensed.
* Check http://android.git.kernel.org/
*/
int git__basename_r(char *buffer, size_t bufflen, const char *path)
{
const char *endp, *startp;
int len, result;
/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
startp = ".";
len = 1;
goto Exit;
}
/* Strip trailing slashes */
endp = path + strlen(path) - 1;
while (endp > path && *endp == '/')
endp--;
/* All slashes becomes "/" */
if (endp == path && *endp == '/') {
startp = "/";
len = 1;
goto Exit;
}
/* Find the start of the base */
startp = endp;
while (startp > path && *(startp - 1) != '/')
startp--;
len = endp - startp +1;
Exit:
result = len;
if (buffer == NULL) {
return result;
}
if (len > (int)bufflen-1) {
len = (int)bufflen-1;
result = GIT_ENOMEM;
}
if (len >= 0) {
memmove(buffer, startp, len);
buffer[len] = 0;
}
return result;
}
/*
* Based on the Android implementation, BSD licensed.
* Check http://android.git.kernel.org/
*/
int git__dirname_r(char *buffer, size_t bufflen, const char *path)
{
const char *endp;
int result, len;
/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
path = ".";
len = 1;
goto Exit;
}
/* Strip trailing slashes */
endp = path + strlen(path) - 1;
while (endp > path && *endp == '/')
endp--;
/* Find the start of the dir */
while (endp > path && *endp != '/')
endp--;
/* Either the dir is "/" or there are no slashes */
if (endp == path) {
path = (*endp == '/') ? "/" : ".";
len = 1;
goto Exit;
}
do {
endp--;
} while (endp > path && *endp == '/');
len = endp - path +1;
Exit:
result = len;
if (len+1 > GIT_PATH_MAX) {
return GIT_ENOMEM;
}
if (buffer == NULL)
return result;
if (len > (int)bufflen-1) {
len = (int)bufflen-1;
result = GIT_ENOMEM;
}
if (len >= 0) {
memmove(buffer, path, len);
buffer[len] = 0;
}
return result;
}
char *git__dirname(const char *path)
{
char *dname = NULL;
int len;
len = (path ? strlen(path) : 0) + 2;
dname = (char *)git__malloc(len);
if (dname == NULL)
return NULL;
if (git__dirname_r(dname, len, path) < GIT_SUCCESS) {
free(dname);
return NULL;
}
return dname;
}
char *git__basename(const char *path)
{
char *bname = NULL;
int len;
len = (path ? strlen(path) : 0) + 2;
bname = (char *)git__malloc(len);
if (bname == NULL)
return NULL;
if (git__basename_r(bname, len, path) < GIT_SUCCESS) {
free(bname);
return NULL;
}
return bname;
}
const char *git__topdir(const char *path)
{
size_t len;
int i;
assert(path);
len = strlen(path);
if (!len || path[len - 1] != '/')
return NULL;
for (i = len - 2; i >= 0; --i)
if (path[i] == '/')
break;
return &path[i + 1];
}
void git__joinpath_n(char *buffer_out, int count, ...)
{
va_list ap;
int i;
char *buffer_start = buffer_out;
va_start(ap, count);
for (i = 0; i < count; ++i) {
const char *path;
int len;
path = va_arg(ap, const char *);
assert((i == 0) || path != buffer_start);
if (i > 0 && *path == '/' && buffer_out > buffer_start && buffer_out[-1] == '/')
path++;
if (!*path)
continue;
len = strlen(path);
memmove(buffer_out, path, len);
buffer_out = buffer_out + len;
if (i < count - 1 && buffer_out[-1] != '/')
*buffer_out++ = '/';
}
va_end(ap);
*buffer_out = '\0';
}
char *git__strtok(char **end, const char *sep) char *git__strtok(char **end, const char *sep)
{ {
char *ptr = *end; char *ptr = *end;
......
...@@ -68,63 +68,9 @@ extern int git__suffixcmp(const char *str, const char *suffix); ...@@ -68,63 +68,9 @@ extern int git__suffixcmp(const char *str, const char *suffix);
extern int git__strtol32(long *n, const char *buff, const char **end_buf, int base); extern int git__strtol32(long *n, const char *buff, const char **end_buf, int base);
/*
* The dirname() function shall take a pointer to a character string
* that contains a pathname, and return a pointer to a string that is a
* pathname of the parent directory of that file. Trailing '/' characters
* in the path are not counted as part of the path.
*
* If path does not contain a '/', then dirname() shall return a pointer to
* the string ".". If path is a null pointer or points to an empty string,
* dirname() shall return a pointer to the string "." .
*
* The `git__dirname` implementation is thread safe. The returned
* string must be manually free'd.
*
* The `git__dirname_r` implementation expects a string allocated
* by the user with big enough size.
*/
extern char *git__dirname(const char *path);
extern int git__dirname_r(char *buffer, size_t bufflen, const char *path);
/*
* This function returns the basename of the file, which is the last
* part of its full name given by fname, with the drive letter and
* leading directories stripped off. For example, the basename of
* c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
*
* Trailing slashes and backslashes are significant: the basename of
* c:/foo/bar/ is an empty string after the rightmost slash.
*
* The `git__basename` implementation is thread safe. The returned
* string must be manually free'd.
*
* The `git__basename_r` implementation expects a string allocated
* by the user with big enough size.
*/
extern char *git__basename(const char *path);
extern int git__basename_r(char *buffer, size_t bufflen, const char *path);
extern const char *git__topdir(const char *path);
/**
* Join two paths together. Takes care of properly fixing the
* middle slashes and everything
*
* The paths are joined together into buffer_out; this is expected
* to be an user allocated buffer of `GIT_PATH_MAX` size
*/
extern void git__joinpath_n(char *buffer_out, int npath, ...);
GIT_INLINE(void) git__joinpath(char *buffer_out, const char *path_a, const char *path_b)
{
git__joinpath_n(buffer_out, 2, path_a, path_b);
}
extern void git__hexdump(const char *buffer, size_t n); extern void git__hexdump(const char *buffer, size_t n);
extern uint32_t git__hash(const void *key, int len, uint32_t seed); extern uint32_t git__hash(const void *key, int len, uint32_t seed);
/** @return true if p fits into the range of a size_t */ /** @return true if p fits into the range of a size_t */
GIT_INLINE(int) git__is_sizet(git_off_t p) GIT_INLINE(int) git__is_sizet(git_off_t p)
{ {
......
#define GIT__WIN32_NO_HIDE_FILEOPS
#include "fileops.h"
#include <errno.h>
int git__unlink(const char *path)
{
chmod(path, 0666);
return unlink(path);
}
int git__mkstemp(char *template)
{
char *file = mktemp(template);
if (file == NULL)
return -1;
return open(file, O_RDWR | O_CREAT | O_BINARY, 0600);
}
int git__fsync(int fd)
{
HANDLE fh = (HANDLE)_get_osfhandle(fd);
if (fh == INVALID_HANDLE_VALUE) {
errno = EBADF;
return -1;
}
if (!FlushFileBuffers(fh)) {
DWORD code = GetLastError();
if (code == ERROR_INVALID_HANDLE)
errno = EINVAL;
else
errno = EIO;
return -1;
}
return 0;
}
...@@ -16,7 +16,7 @@ static DWORD get_page_size(void) ...@@ -16,7 +16,7 @@ static DWORD get_page_size(void)
return page_size; return page_size;
} }
int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
{ {
HANDLE fh = (HANDLE)_get_osfhandle(fd); HANDLE fh = (HANDLE)_get_osfhandle(fd);
DWORD page_size = get_page_size(); DWORD page_size = get_page_size();
...@@ -92,7 +92,7 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t o ...@@ -92,7 +92,7 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t o
return GIT_SUCCESS; return GIT_SUCCESS;
} }
int git__munmap(git_map *map) int p_munmap(git_map *map)
{ {
assert(map != NULL); assert(map != NULL);
......
#include "posix.h"
#include <errno.h>
int p_unlink(const char *path)
{
chmod(path, 0666);
return unlink(path);
}
int p_fsync(int fd)
{
HANDLE fh = (HANDLE)_get_osfhandle(fd);
if (fh == INVALID_HANDLE_VALUE) {
errno = EBADF;
return -1;
}
if (!FlushFileBuffers(fh)) {
DWORD code = GetLastError();
if (code == ERROR_INVALID_HANDLE)
errno = EINVAL;
else
errno = EIO;
return -1;
}
return 0;
}
GIT_INLINE(time_t) filetime_to_time_t(const FILETIME *ft)
{
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */
winTime /= 10000000; /* Nano to seconds resolution */
return (time_t)winTime;
}
static int do_lstat(const char *file_name, struct stat *buf)
{
WIN32_FILE_ATTRIBUTE_DATA fdata;
if (GetFileAttributesExA(file_name, GetFileExInfoStandard, &fdata)) {
int fMode = S_IREAD;
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
fMode |= S_IFDIR;
else
fMode |= S_IFREG;
if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
fMode |= S_IWRITE;
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
fMode |= S_IFLNK;
buf->st_ino = 0;
buf->st_gid = 0;
buf->st_uid = 0;
buf->st_nlink = 1;
buf->st_mode = (mode_t)fMode;
buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
buf->st_dev = buf->st_rdev = (_getdrive() - 1);
buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
return GIT_SUCCESS;
}
switch (GetLastError()) {
case ERROR_ACCESS_DENIED:
case ERROR_SHARING_VIOLATION:
case ERROR_LOCK_VIOLATION:
case ERROR_SHARING_BUFFER_EXCEEDED:
return GIT_EOSERR;
case ERROR_BUFFER_OVERFLOW:
case ERROR_NOT_ENOUGH_MEMORY:
return GIT_ENOMEM;
default:
return GIT_EINVALIDPATH;
}
}
int p_lstat(const char *file_name, struct stat *buf)
{
int namelen, error;
char alt_name[GIT_PATH_MAX];
if ((error = do_lstat(file_name, buf)) == GIT_SUCCESS)
return GIT_SUCCESS;
/* if file_name ended in a '/', Windows returned ENOENT;
* try again without trailing slashes
*/
if (error != GIT_EINVALIDPATH)
return git__throw(GIT_EOSERR, "Failed to lstat file");
namelen = strlen(file_name);
if (namelen && file_name[namelen-1] != '/')
return git__throw(GIT_EOSERR, "Failed to lstat file");
while (namelen && file_name[namelen-1] == '/')
--namelen;
if (!namelen || namelen >= GIT_PATH_MAX)
return git__throw(GIT_ENOMEM, "Failed to lstat file");
memcpy(alt_name, file_name, namelen);
alt_name[namelen] = 0;
return do_lstat(alt_name, buf);
}
int p_readlink(const char *link, char *target, size_t target_len)
{
typedef DWORD (WINAPI *fpath_func)(HANDLE, LPTSTR, DWORD, DWORD);
static fpath_func pGetFinalPath = NULL;
HANDLE hFile;
DWORD dwRet;
/*
* Try to load the pointer to pGetFinalPath dynamically, because
* it is not available in platforms older than Vista
*/
if (pGetFinalPath == NULL) {
HINSTANCE library = LoadLibrary("kernel32");
if (library != NULL)
pGetFinalPath = (fpath_func)GetProcAddress(library, "GetFinalPathNameByHandleA");
if (pGetFinalPath == NULL)
return git__throw(GIT_EOSERR,
"'GetFinalPathNameByHandleA' is not available in this platform");
}
hFile = CreateFile(link, // file to open
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_FLAG_BACKUP_SEMANTICS, // normal file
NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE)
return GIT_EOSERR;
dwRet = pGetFinalPath(hFile, target, target_len, 0x0);
if (dwRet >= target_len)
return GIT_ENOMEM;
CloseHandle(hFile);
if (dwRet > 4) {
/* Skip first 4 characters if they are "\\?\" */
if (target[0] == '\\' && target[1] == '\\' && target[2] == '?' && target[3] == '\\') {
char tmp[GIT_PATH_MAX];
unsigned int offset = 4;
dwRet -= 4;
/* \??\UNC\ */
if (dwRet > 7 && target[4] == 'U' && target[5] == 'N' && target[6] == 'C') {
offset += 2;
dwRet -= 2;
target[offset] = '\\';
}
memcpy(tmp, target + offset, dwRet);
memcpy(target, tmp, dwRet);
}
}
target[dwRet] = '\0';
return dwRet;
}
int p_hide_directory__w32(const char *path)
{
int error;
error = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN) != 0 ?
GIT_SUCCESS : GIT_ERROR; /* MSDN states a "non zero" value indicates a success */
if (error < GIT_SUCCESS)
error = git__throw(GIT_EOSERR, "Failed to hide directory '%s'", path);
return error;
}
#ifndef INCLUDE_posix__w32_h__
#define INCLUDE_posix__w32_h__
#include "common.h"
GIT_INLINE(int) p_link(const char *GIT_UNUSED(old), const char *GIT_UNUSED(new))
{
GIT_UNUSED_ARG(old)
GIT_UNUSED_ARG(new)
errno = ENOSYS;
return -1;
}
GIT_INLINE(int) p_mkdir(const char *path, int GIT_UNUSED(mode))
{
GIT_UNUSED_ARG(mode)
return mkdir(path);
}
extern int p_unlink(const char *path);
extern int p_lstat(const char *file_name, struct stat *buf);
extern int p_readlink(const char *link, char *target, size_t target_len);
extern int p_hide_directory__w32(const char *path);
#endif
...@@ -78,9 +78,9 @@ BEGIN_TEST(path0, "get the dirname of a path") ...@@ -78,9 +78,9 @@ BEGIN_TEST(path0, "get the dirname of a path")
char dir[64], *dir2; char dir[64], *dir2;
#define DIRNAME_TEST(A, B) { \ #define DIRNAME_TEST(A, B) { \
must_be_true(git__dirname_r(dir, sizeof(dir), A) >= 0); \ must_be_true(git_path_dirname_r(dir, sizeof(dir), A) >= 0); \
must_be_true(strcmp(dir, B) == 0); \ must_be_true(strcmp(dir, B) == 0); \
must_be_true((dir2 = git__dirname(A)) != NULL); \ must_be_true((dir2 = git_path_dirname(A)) != NULL); \
must_be_true(strcmp(dir2, B) == 0); \ must_be_true(strcmp(dir2, B) == 0); \
free(dir2); \ free(dir2); \
} }
...@@ -107,9 +107,9 @@ BEGIN_TEST(path1, "get the base name of a path") ...@@ -107,9 +107,9 @@ BEGIN_TEST(path1, "get the base name of a path")
char base[64], *base2; char base[64], *base2;
#define BASENAME_TEST(A, B) { \ #define BASENAME_TEST(A, B) { \
must_be_true(git__basename_r(base, sizeof(base), A) >= 0); \ must_be_true(git_path_basename_r(base, sizeof(base), A) >= 0); \
must_be_true(strcmp(base, B) == 0); \ must_be_true(strcmp(base, B) == 0); \
must_be_true((base2 = git__basename(A)) != NULL); \ must_be_true((base2 = git_path_basename(A)) != NULL); \
must_be_true(strcmp(base2, B) == 0); \ must_be_true(strcmp(base2, B) == 0); \
free(base2); \ free(base2); \
} }
...@@ -132,7 +132,7 @@ BEGIN_TEST(path2, "get the latest component in a path") ...@@ -132,7 +132,7 @@ BEGIN_TEST(path2, "get the latest component in a path")
const char *dir; const char *dir;
#define TOPDIR_TEST(A, B) { \ #define TOPDIR_TEST(A, B) { \
must_be_true((dir = git__topdir(A)) != NULL); \ must_be_true((dir = git_path_topdir(A)) != NULL); \
must_be_true(strcmp(dir, B) == 0); \ must_be_true(strcmp(dir, B) == 0); \
} }
...@@ -144,10 +144,10 @@ BEGIN_TEST(path2, "get the latest component in a path") ...@@ -144,10 +144,10 @@ BEGIN_TEST(path2, "get the latest component in a path")
TOPDIR_TEST("/", "/"); TOPDIR_TEST("/", "/");
TOPDIR_TEST("a/", "a/"); TOPDIR_TEST("a/", "a/");
must_be_true(git__topdir("/usr/.git") == NULL); must_be_true(git_path_topdir("/usr/.git") == NULL);
must_be_true(git__topdir(".") == NULL); must_be_true(git_path_topdir(".") == NULL);
must_be_true(git__topdir("") == NULL); must_be_true(git_path_topdir("") == NULL);
must_be_true(git__topdir("a") == NULL); must_be_true(git_path_topdir("a") == NULL);
#undef TOPDIR_TEST #undef TOPDIR_TEST
END_TEST END_TEST
...@@ -165,7 +165,7 @@ static int ensure_normalized(const char *input_path, const char *expected_path, ...@@ -165,7 +165,7 @@ static int ensure_normalized(const char *input_path, const char *expected_path,
char buffer_out[GIT_PATH_MAX]; char buffer_out[GIT_PATH_MAX];
char current_workdir[GIT_PATH_MAX]; char current_workdir[GIT_PATH_MAX];
error = gitfo_getcwd(current_workdir, sizeof(current_workdir)); error = p_getcwd(current_workdir, sizeof(current_workdir));
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return error; return error;
...@@ -193,12 +193,12 @@ static int ensure_normalized(const char *input_path, const char *expected_path, ...@@ -193,12 +193,12 @@ static int ensure_normalized(const char *input_path, const char *expected_path,
static int ensure_dir_path_normalized(const char *input_path, const char *expected_path, int assert_flags) static int ensure_dir_path_normalized(const char *input_path, const char *expected_path, int assert_flags)
{ {
return ensure_normalized(input_path, expected_path, gitfo_prettify_dir_path, assert_flags); return ensure_normalized(input_path, expected_path, git_futils_prettify_dir, assert_flags);
} }
static int ensure_file_path_normalized(const char *input_path, const char *expected_path, int assert_flags) static int ensure_file_path_normalized(const char *input_path, const char *expected_path, int assert_flags)
{ {
return ensure_normalized(input_path, expected_path, gitfo_prettify_file_path, assert_flags); return ensure_normalized(input_path, expected_path, git_futils_prettyify_file, assert_flags);
} }
BEGIN_TEST(path3, "prettify and validate a path to a file") BEGIN_TEST(path3, "prettify and validate a path to a file")
...@@ -355,7 +355,7 @@ END_TEST ...@@ -355,7 +355,7 @@ END_TEST
static int ensure_joinpath(const char *path_a, const char *path_b, const char *expected_path) static int ensure_joinpath(const char *path_a, const char *path_b, const char *expected_path)
{ {
char joined_path[GIT_PATH_MAX]; char joined_path[GIT_PATH_MAX];
git__joinpath(joined_path, path_a, path_b); git_path_join(joined_path, path_a, path_b);
return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR; return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR;
} }
...@@ -377,7 +377,7 @@ END_TEST ...@@ -377,7 +377,7 @@ END_TEST
static int ensure_joinpath_n(const char *path_a, const char *path_b, const char *path_c, const char *path_d, const char *expected_path) static int ensure_joinpath_n(const char *path_a, const char *path_b, const char *path_c, const char *path_d, const char *expected_path)
{ {
char joined_path[GIT_PATH_MAX]; char joined_path[GIT_PATH_MAX];
git__joinpath_n(joined_path, 4, path_a, path_b, path_c, path_d); git_path_join_n(joined_path, 4, path_a, path_b, path_c, path_d);
return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR; return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR;
} }
...@@ -411,14 +411,14 @@ BEGIN_TEST(path7, "prevent a path which escapes the root directory from being pr ...@@ -411,14 +411,14 @@ BEGIN_TEST(path7, "prevent a path which escapes the root directory from being pr
char prettified[GIT_PATH_MAX]; char prettified[GIT_PATH_MAX];
int i = 0, number_to_escape; int i = 0, number_to_escape;
must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir))); must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
number_to_escape = count_number_of_path_segments(current_workdir); number_to_escape = count_number_of_path_segments(current_workdir);
for (i = 0; i < number_to_escape + 1; i++) for (i = 0; i < number_to_escape + 1; i++)
git__joinpath(current_workdir, current_workdir, "../"); git_path_join(current_workdir, current_workdir, "../");
must_fail(gitfo_prettify_dir_path(prettified, sizeof(prettified), current_workdir, NULL)); must_fail(git_futils_prettify_dir(prettified, sizeof(prettified), current_workdir, NULL));
END_TEST END_TEST
typedef struct name_data { typedef struct name_data {
...@@ -451,24 +451,24 @@ static int setup(walk_data *d) ...@@ -451,24 +451,24 @@ static int setup(walk_data *d)
{ {
name_data *n; name_data *n;
if (gitfo_mkdir(top_dir, 0755) < 0) if (p_mkdir(top_dir, 0755) < 0)
return error("can't mkdir(\"%s\")", top_dir); return error("can't mkdir(\"%s\")", top_dir);
if (gitfo_chdir(top_dir) < 0) if (p_chdir(top_dir) < 0)
return error("can't chdir(\"%s\")", top_dir); return error("can't chdir(\"%s\")", top_dir);
if (strcmp(d->sub, ".") != 0) if (strcmp(d->sub, ".") != 0)
if (gitfo_mkdir(d->sub, 0755) < 0) if (p_mkdir(d->sub, 0755) < 0)
return error("can't mkdir(\"%s\")", d->sub); return error("can't mkdir(\"%s\")", d->sub);
strcpy(path_buffer, d->sub); strcpy(path_buffer, d->sub);
state_loc = d; state_loc = d;
for (n = d->names; n->name; n++) { for (n = d->names; n->name; n++) {
git_file fd = gitfo_creat(n->name, 0600); git_file fd = p_creat(n->name, 0600);
if (fd < 0) if (fd < 0)
return GIT_ERROR; return GIT_ERROR;
gitfo_close(fd); p_close(fd);
n->count = 0; n->count = 0;
} }
...@@ -480,18 +480,18 @@ static int knockdown(walk_data *d) ...@@ -480,18 +480,18 @@ static int knockdown(walk_data *d)
name_data *n; name_data *n;
for (n = d->names; n->name; n++) { for (n = d->names; n->name; n++) {
if (gitfo_unlink(n->name) < 0) if (p_unlink(n->name) < 0)
return error("can't unlink(\"%s\")", n->name); return error("can't unlink(\"%s\")", n->name);
} }
if (strcmp(d->sub, ".") != 0) if (strcmp(d->sub, ".") != 0)
if (gitfo_rmdir(d->sub) < 0) if (p_rmdir(d->sub) < 0)
return error("can't rmdir(\"%s\")", d->sub); return error("can't rmdir(\"%s\")", d->sub);
if (gitfo_chdir("..") < 0) if (p_chdir("..") < 0)
return error("can't chdir(\"..\")"); return error("can't chdir(\"..\")");
if (gitfo_rmdir(top_dir) < 0) if (p_rmdir(top_dir) < 0)
return error("can't rmdir(\"%s\")", top_dir); return error("can't rmdir(\"%s\")", top_dir);
return 0; return 0;
...@@ -546,7 +546,7 @@ BEGIN_TEST(dirent0, "make sure that the '.' folder is not traversed") ...@@ -546,7 +546,7 @@ BEGIN_TEST(dirent0, "make sure that the '.' folder is not traversed")
must_pass(setup(&dot)); must_pass(setup(&dot));
must_pass(gitfo_dirent(path_buffer, must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&dot)); &dot));
...@@ -571,7 +571,7 @@ BEGIN_TEST(dirent1, "traverse a subfolder") ...@@ -571,7 +571,7 @@ BEGIN_TEST(dirent1, "traverse a subfolder")
must_pass(setup(&sub)); must_pass(setup(&sub));
must_pass(gitfo_dirent(path_buffer, must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&sub)); &sub));
...@@ -590,7 +590,7 @@ BEGIN_TEST(dirent2, "traverse a slash-terminated subfolder") ...@@ -590,7 +590,7 @@ BEGIN_TEST(dirent2, "traverse a slash-terminated subfolder")
must_pass(setup(&sub_slash)); must_pass(setup(&sub_slash));
must_pass(gitfo_dirent(path_buffer, must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&sub_slash)); &sub_slash));
...@@ -619,7 +619,7 @@ BEGIN_TEST(dirent3, "make sure that empty folders are not traversed") ...@@ -619,7 +619,7 @@ BEGIN_TEST(dirent3, "make sure that empty folders are not traversed")
must_pass(setup(&empty)); must_pass(setup(&empty));
must_pass(gitfo_dirent(path_buffer, must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&empty)); &empty));
...@@ -627,7 +627,7 @@ BEGIN_TEST(dirent3, "make sure that empty folders are not traversed") ...@@ -627,7 +627,7 @@ BEGIN_TEST(dirent3, "make sure that empty folders are not traversed")
must_pass(check_counts(&empty)); must_pass(check_counts(&empty));
/* make sure callback not called */ /* make sure callback not called */
must_pass(gitfo_dirent(path_buffer, must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
dont_call_me, dont_call_me,
&empty)); &empty));
...@@ -652,7 +652,7 @@ BEGIN_TEST(dirent4, "make sure that strange looking filenames ('..c') are traver ...@@ -652,7 +652,7 @@ BEGIN_TEST(dirent4, "make sure that strange looking filenames ('..c') are traver
must_pass(setup(&odd)); must_pass(setup(&odd));
must_pass(gitfo_dirent(path_buffer, must_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&odd)); &odd));
...@@ -667,12 +667,12 @@ BEGIN_TEST(filebuf0, "make sure git_filebuf_open doesn't delete an existing lock ...@@ -667,12 +667,12 @@ BEGIN_TEST(filebuf0, "make sure git_filebuf_open doesn't delete an existing lock
int fd; int fd;
char test[] = "test", testlock[] = "test.lock"; char test[] = "test", testlock[] = "test.lock";
fd = gitfo_creat(testlock, 0744); fd = p_creat(testlock, 0744);
must_pass(fd); must_pass(fd);
must_pass(gitfo_close(fd)); must_pass(p_close(fd));
must_fail(git_filebuf_open(&file, test, 0)); must_fail(git_filebuf_open(&file, test, 0));
must_pass(gitfo_exists(testlock)); must_pass(git_futils_exists(testlock));
must_pass(gitfo_unlink(testlock)); must_pass(p_unlink(testlock));
END_TEST END_TEST
BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected") BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected")
...@@ -680,16 +680,16 @@ BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected") ...@@ -680,16 +680,16 @@ BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected")
int fd; int fd;
char test[] = "test"; char test[] = "test";
fd = gitfo_creat(test, 0644); fd = p_creat(test, 0644);
must_pass(fd); must_pass(fd);
must_pass(gitfo_write(fd, "libgit2 rocks\n", 14)); must_pass(p_write(fd, "libgit2 rocks\n", 14));
must_pass(gitfo_close(fd)); must_pass(p_close(fd));
must_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND)); must_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
must_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); must_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
must_pass(git_filebuf_commit(&file)); must_pass(git_filebuf_commit(&file));
must_pass(gitfo_unlink(test)); must_pass(p_unlink(test));
END_TEST END_TEST
BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly") BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly")
...@@ -702,7 +702,7 @@ BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly" ...@@ -702,7 +702,7 @@ BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly"
must_pass(git_filebuf_write(&file, buf, sizeof(buf))); must_pass(git_filebuf_write(&file, buf, sizeof(buf)));
must_pass(git_filebuf_commit(&file)); must_pass(git_filebuf_commit(&file));
must_pass(gitfo_unlink(test)); must_pass(p_unlink(test));
END_TEST END_TEST
BEGIN_SUITE(core) BEGIN_SUITE(core)
......
...@@ -31,7 +31,7 @@ static char *odb_dir = "test-objects"; ...@@ -31,7 +31,7 @@ static char *odb_dir = "test-objects";
static int make_odb_dir(void) static int make_odb_dir(void)
{ {
if (gitfo_mkdir(odb_dir, 0755) < 0) { if (p_mkdir(odb_dir, 0755) < 0) {
int err = errno; int err = errno;
fprintf(stderr, "can't make directory \"%s\"", odb_dir); fprintf(stderr, "can't make directory \"%s\"", odb_dir);
if (err == EEXIST) if (err == EEXIST)
...@@ -44,9 +44,9 @@ static int make_odb_dir(void) ...@@ -44,9 +44,9 @@ static int make_odb_dir(void)
static int check_object_files(object_data *d) static int check_object_files(object_data *d)
{ {
if (gitfo_exists(d->dir) < 0) if (git_futils_exists(d->dir) < 0)
return -1; return -1;
if (gitfo_exists(d->file) < 0) if (git_futils_exists(d->file) < 0)
return -1; return -1;
return 0; return 0;
} }
...@@ -64,16 +64,16 @@ static int cmp_objects(git_rawobj *o1, git_rawobj *o2) ...@@ -64,16 +64,16 @@ static int cmp_objects(git_rawobj *o1, git_rawobj *o2)
static int remove_object_files(object_data *d) static int remove_object_files(object_data *d)
{ {
if (gitfo_unlink(d->file) < 0) { if (p_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file); fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1; return -1;
} }
if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) { if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove directory \"%s\"\n", d->dir); fprintf(stderr, "can't remove directory \"%s\"\n", d->dir);
return -1; return -1;
} }
if (gitfo_rmdir(odb_dir) < 0) { if (p_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir); fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir);
return -1; return -1;
} }
......
...@@ -146,7 +146,7 @@ BEGIN_TEST(write0, "write an index back to disk") ...@@ -146,7 +146,7 @@ BEGIN_TEST(write0, "write an index back to disk")
git_index_free(index); git_index_free(index);
gitfo_unlink("index_rewrite"); p_unlink("index_rewrite");
END_TEST END_TEST
BEGIN_TEST(sort0, "sort the entires in an index") BEGIN_TEST(sort0, "sort the entires in an index")
...@@ -187,7 +187,7 @@ BEGIN_TEST(add0, "add a new file to the index") ...@@ -187,7 +187,7 @@ BEGIN_TEST(add0, "add a new file to the index")
must_pass(git_index_entrycount(index) == 0); must_pass(git_index_entrycount(index) == 0);
/* Create a new file in the working directory */ /* Create a new file in the working directory */
must_pass(gitfo_mkdir_2file(TEMP_REPO_FOLDER "myrepo/test.txt")); must_pass(git_futils_mkpath2file(TEMP_REPO_FOLDER "myrepo/test.txt"));
must_pass(git_filebuf_open(&file, TEMP_REPO_FOLDER "myrepo/test.txt", 0)); must_pass(git_filebuf_open(&file, TEMP_REPO_FOLDER "myrepo/test.txt", 0));
must_pass(git_filebuf_write(&file, "hey there\n", 10)); must_pass(git_filebuf_write(&file, "hey there\n", 10));
must_pass(git_filebuf_commit(&file)); must_pass(git_filebuf_commit(&file));
......
...@@ -48,7 +48,7 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference") ...@@ -48,7 +48,7 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference")
must_be_true(git_object_type(object) == GIT_OBJ_TAG); must_be_true(git_object_type(object) == GIT_OBJ_TAG);
/* Ensure the name of the tag matches the name of the reference */ /* Ensure the name of the tag matches the name of the reference */
git__joinpath(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)); git_path_join(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object));
must_be_true(strcmp(ref_name_from_tag_name, loose_tag_ref_name) == 0); must_be_true(strcmp(ref_name_from_tag_name, loose_tag_ref_name) == 0);
git_object_close(object); git_object_close(object);
...@@ -209,7 +209,7 @@ BEGIN_TEST(create0, "create a new symbolic reference") ...@@ -209,7 +209,7 @@ BEGIN_TEST(create0, "create a new symbolic reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Retrieve the physical path to the symbolic ref for further cleaning */ /* Retrieve the physical path to the symbolic ref for further cleaning */
git__joinpath(ref_path, repo->path_repository, new_head_tracker); git_path_join(ref_path, repo->path_repository, new_head_tracker);
/* Create and write the new symbolic reference */ /* Create and write the new symbolic reference */
must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0));
...@@ -251,7 +251,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference") ...@@ -251,7 +251,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
git__joinpath(ref_path, repo->path_repository, new_head_tracker); git_path_join(ref_path, repo->path_repository, new_head_tracker);
must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0));
must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker));
must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); must_pass(git_reference_resolve(&resolved_ref, looked_up_ref));
...@@ -273,7 +273,7 @@ BEGIN_TEST(create2, "create a new OID reference") ...@@ -273,7 +273,7 @@ BEGIN_TEST(create2, "create a new OID reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Retrieve the physical path to the symbolic ref for further cleaning */ /* Retrieve the physical path to the symbolic ref for further cleaning */
git__joinpath(ref_path, repo->path_repository, new_head); git_path_join(ref_path, repo->path_repository, new_head);
/* Create and write the new object id reference */ /* Create and write the new object id reference */
must_pass(git_reference_create_oid(&new_reference, repo, new_head, &id, 0)); must_pass(git_reference_create_oid(&new_reference, repo, new_head, &id, 0));
...@@ -432,8 +432,8 @@ BEGIN_TEST(pack0, "create a packfile for an empty folder") ...@@ -432,8 +432,8 @@ BEGIN_TEST(pack0, "create a packfile for an empty folder")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
git__joinpath_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir"); git_path_join_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir");
must_pass(gitfo_mkdir_recurs(temp_path, mode)); must_pass(git_futils_mkdir_r(temp_path, mode));
must_pass(git_reference_packall(repo)); must_pass(git_reference_packall(repo));
...@@ -460,8 +460,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo") ...@@ -460,8 +460,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_pass(git_reference_packall(repo)); must_pass(git_reference_packall(repo));
/* Ensure the packed-refs file exists */ /* Ensure the packed-refs file exists */
git__joinpath(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE); git_path_join(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE);
must_pass(gitfo_exists(temp_path)); must_pass(git_futils_exists(temp_path));
/* Ensure the known ref can still be looked up but is now packed */ /* Ensure the known ref can still be looked up but is now packed */
must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name));
...@@ -469,8 +469,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo") ...@@ -469,8 +469,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
/* Ensure the known ref has been removed from the loose folder structure */ /* Ensure the known ref has been removed from the loose folder structure */
git__joinpath(temp_path, repo->path_repository, loose_tag_ref_name); git_path_join(temp_path, repo->path_repository, loose_tag_ref_name);
must_pass(!gitfo_exists(temp_path)); must_pass(!git_futils_exists(temp_path));
close_temp_repo(repo); close_temp_repo(repo);
END_TEST END_TEST
...@@ -484,8 +484,8 @@ BEGIN_TEST(rename0, "rename a loose reference") ...@@ -484,8 +484,8 @@ BEGIN_TEST(rename0, "rename a loose reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the ref doesn't exist on the file system */ /* Ensure the ref doesn't exist on the file system */
git__joinpath(temp_path, repo->path_repository, new_name); git_path_join(temp_path, repo->path_repository, new_name);
must_pass(!gitfo_exists(temp_path)); must_pass(!git_futils_exists(temp_path));
/* Retrieval of the reference to rename */ /* Retrieval of the reference to rename */
must_pass(git_reference_lookup(&looked_up_ref, repo, loose_tag_ref_name)); must_pass(git_reference_lookup(&looked_up_ref, repo, loose_tag_ref_name));
...@@ -509,8 +509,8 @@ BEGIN_TEST(rename0, "rename a loose reference") ...@@ -509,8 +509,8 @@ BEGIN_TEST(rename0, "rename a loose reference")
must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0);
/* ...and the ref can be found in the file system */ /* ...and the ref can be found in the file system */
git__joinpath(temp_path, repo->path_repository, new_name); git_path_join(temp_path, repo->path_repository, new_name);
must_pass(gitfo_exists(temp_path)); must_pass(git_futils_exists(temp_path));
close_temp_repo(repo); close_temp_repo(repo);
END_TEST END_TEST
...@@ -524,8 +524,8 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)") ...@@ -524,8 +524,8 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the ref doesn't exist on the file system */ /* Ensure the ref doesn't exist on the file system */
git__joinpath(temp_path, repo->path_repository, packed_head_name); git_path_join(temp_path, repo->path_repository, packed_head_name);
must_pass(!gitfo_exists(temp_path)); must_pass(!git_futils_exists(temp_path));
/* The reference can however be looked-up... */ /* The reference can however be looked-up... */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
...@@ -549,8 +549,8 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)") ...@@ -549,8 +549,8 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0);
/* ...and the ref now happily lives in the file system */ /* ...and the ref now happily lives in the file system */
git__joinpath(temp_path, repo->path_repository, brand_new_name); git_path_join(temp_path, repo->path_repository, brand_new_name);
must_pass(gitfo_exists(temp_path)); must_pass(git_futils_exists(temp_path));
close_temp_repo(repo); close_temp_repo(repo);
END_TEST END_TEST
...@@ -564,8 +564,8 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference ...@@ -564,8 +564,8 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the other reference exists on the file system */ /* Ensure the other reference exists on the file system */
git__joinpath(temp_path, repo->path_repository, packed_test_head_name); git_path_join(temp_path, repo->path_repository, packed_test_head_name);
must_pass(gitfo_exists(temp_path)); must_pass(git_futils_exists(temp_path));
/* Lookup the other reference */ /* Lookup the other reference */
must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
...@@ -589,7 +589,7 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference ...@@ -589,7 +589,7 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference
must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0);
/* Ensure the other ref still exists on the file system */ /* Ensure the other ref still exists on the file system */
must_pass(gitfo_exists(temp_path)); must_pass(git_futils_exists(temp_path));
close_temp_repo(repo); close_temp_repo(repo);
END_TEST END_TEST
...@@ -694,8 +694,8 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove ...@@ -694,8 +694,8 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the loose reference exists on the file system */ /* Ensure the loose reference exists on the file system */
git__joinpath(temp_path, repo->path_repository, packed_test_head_name); git_path_join(temp_path, repo->path_repository, packed_test_head_name);
must_pass(gitfo_exists(temp_path)); must_pass(git_futils_exists(temp_path));
/* Lookup the reference */ /* Lookup the reference */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name)); must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));
...@@ -710,7 +710,7 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove ...@@ -710,7 +710,7 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove
must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
/* Ensure the loose reference doesn't exist any longer on the file system */ /* Ensure the loose reference doesn't exist any longer on the file system */
must_pass(!gitfo_exists(temp_path)); must_pass(!git_futils_exists(temp_path));
close_temp_repo(repo); close_temp_repo(repo);
END_TEST END_TEST
......
...@@ -104,10 +104,10 @@ static int ensure_repository_init( ...@@ -104,10 +104,10 @@ static int ensure_repository_init(
char path_odb[GIT_PATH_MAX]; char path_odb[GIT_PATH_MAX];
git_repository *repo; git_repository *repo;
if (gitfo_isdir(working_directory) == GIT_SUCCESS) if (git_futils_isdir(working_directory) == GIT_SUCCESS)
return GIT_ERROR; return GIT_ERROR;
git__joinpath(path_odb, expected_path_repository, GIT_OBJECTS_DIR); git_path_join(path_odb, expected_path_repository, GIT_OBJECTS_DIR);
if (git_repository_init(&repo, working_directory, repository_kind) < GIT_SUCCESS) if (git_repository_init(&repo, working_directory, repository_kind) < GIT_SUCCESS)
return GIT_ERROR; return GIT_ERROR;
...@@ -154,8 +154,8 @@ cleanup: ...@@ -154,8 +154,8 @@ cleanup:
BEGIN_TEST(init0, "initialize a standard repo") BEGIN_TEST(init0, "initialize a standard repo")
char path_index[GIT_PATH_MAX], path_repository[GIT_PATH_MAX]; char path_index[GIT_PATH_MAX], path_repository[GIT_PATH_MAX];
git__joinpath(path_repository, TEMP_REPO_FOLDER, GIT_DIR); git_path_join(path_repository, TEMP_REPO_FOLDER, GIT_DIR);
git__joinpath(path_index, path_repository, GIT_INDEX_FILE); git_path_join(path_index, path_repository, GIT_INDEX_FILE);
must_pass(ensure_repository_init(TEMP_REPO_FOLDER, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER)); must_pass(ensure_repository_init(TEMP_REPO_FOLDER, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER));
must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER)); must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER));
...@@ -164,7 +164,7 @@ END_TEST ...@@ -164,7 +164,7 @@ END_TEST
BEGIN_TEST(init1, "initialize a bare repo") BEGIN_TEST(init1, "initialize a bare repo")
char path_repository[GIT_PATH_MAX]; char path_repository[GIT_PATH_MAX];
git__joinpath(path_repository, TEMP_REPO_FOLDER, ""); git_path_join(path_repository, TEMP_REPO_FOLDER, "");
must_pass(ensure_repository_init(TEMP_REPO_FOLDER, BARE_REPOSITORY, NULL, path_repository, NULL)); must_pass(ensure_repository_init(TEMP_REPO_FOLDER, BARE_REPOSITORY, NULL, path_repository, NULL));
must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, BARE_REPOSITORY, NULL, path_repository, NULL)); must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, BARE_REPOSITORY, NULL, path_repository, NULL));
...@@ -176,10 +176,10 @@ BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping ...@@ -176,10 +176,10 @@ BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping
const int mode = 0755; /* or 0777 ? */ const int mode = 0755; /* or 0777 ? */
git_repository* repo; git_repository* repo;
must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir))); must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
git__joinpath(path_repository, TEMP_REPO_FOLDER, "a/b/c/"); git_path_join(path_repository, TEMP_REPO_FOLDER, "a/b/c/");
must_pass(gitfo_mkdir_recurs(path_repository, mode)); must_pass(git_futils_mkdir_r(path_repository, mode));
must_pass(chdir(path_repository)); must_pass(chdir(path_repository));
...@@ -242,14 +242,14 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t ...@@ -242,14 +242,14 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t
git_repository* repo; git_repository* repo;
/* Setup the repository to open */ /* Setup the repository to open */
must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir))); must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
strcpy(path_repository, current_workdir); strcpy(path_repository, current_workdir);
git__joinpath_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git"); git_path_join_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git");
must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository)); must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository));
/* Change the current working directory */ /* Change the current working directory */
git__joinpath(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/"); git_path_join(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/");
must_pass(gitfo_mkdir_recurs(new_current_workdir, mode)); must_pass(git_futils_mkdir_r(new_current_workdir, mode));
must_pass(chdir(new_current_workdir)); must_pass(chdir(new_current_workdir));
must_pass(git_repository_open(&repo, "../../d/e.git")); must_pass(git_repository_open(&repo, "../../d/e.git"));
...@@ -350,20 +350,20 @@ static int write_file(const char *path, const char *content) ...@@ -350,20 +350,20 @@ static int write_file(const char *path, const char *content)
int error; int error;
git_file file; git_file file;
if (gitfo_exists(path) == GIT_SUCCESS) { if (git_futils_exists(path) == GIT_SUCCESS) {
error = gitfo_unlink(path); error = p_unlink(path);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return error; return error;
} }
file = gitfo_creat_force(path, 0644); file = git_futils_creat_withpath(path, 0644);
if (file < GIT_SUCCESS) if (file < GIT_SUCCESS)
return file; return file;
error = gitfo_write(file, (void*)content, strlen(content) * sizeof(char)); error = p_write(file, (void*)content, strlen(content) * sizeof(char));
gitfo_close(file); p_close(file);
return error; return error;
} }
...@@ -374,7 +374,7 @@ static int append_ceiling_dir(char *ceiling_dirs, const char *path) ...@@ -374,7 +374,7 @@ static int append_ceiling_dir(char *ceiling_dirs, const char *path)
int len = strlen(ceiling_dirs); int len = strlen(ceiling_dirs);
int error; int error;
error = gitfo_prettify_dir_path(ceiling_dirs + len + (len ? 1 : 0), GIT_PATH_MAX, path, NULL); error = git_futils_prettify_dir(ceiling_dirs + len + (len ? 1 : 0), GIT_PATH_MAX, path, NULL);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to append ceiling directory."); return git__rethrow(error, "Failed to append ceiling directory.");
...@@ -394,7 +394,7 @@ BEGIN_TEST(discover0, "test discover") ...@@ -394,7 +394,7 @@ BEGIN_TEST(discover0, "test discover")
rmdir_recurs(DISCOVER_FOLDER); rmdir_recurs(DISCOVER_FOLDER);
must_pass(append_ceiling_dir(ceiling_dirs,TEST_RESOURCES)); must_pass(append_ceiling_dir(ceiling_dirs,TEST_RESOURCES));
gitfo_mkdir_recurs(DISCOVER_FOLDER, mode); git_futils_mkdir_r(DISCOVER_FOLDER, mode);
must_be_true(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO); must_be_true(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO);
...@@ -403,15 +403,15 @@ BEGIN_TEST(discover0, "test discover") ...@@ -403,15 +403,15 @@ BEGIN_TEST(discover0, "test discover")
git_repository_free(repo); git_repository_free(repo);
must_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0)); must_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0));
must_pass(gitfo_mkdir_recurs(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
must_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs)); must_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
must_pass(gitfo_mkdir_recurs(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path)); must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path)); must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(gitfo_mkdir_recurs(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode)); must_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT)); must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT)); must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../")); must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../"));
...@@ -420,13 +420,13 @@ BEGIN_TEST(discover0, "test discover") ...@@ -420,13 +420,13 @@ BEGIN_TEST(discover0, "test discover")
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path)); must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path));
must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER1, mode)); must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:")); must_pass(write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:"));
must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER2, mode)); must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:")); must_pass(write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:"));
must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER3, mode)); must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n")); must_pass(write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n"));
must_pass(gitfo_mkdir_recurs(ALTERNATE_NOT_FOUND_FOLDER, mode)); must_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, mode));
must_pass(write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist")); must_pass(write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist"));
must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs)); must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs));
must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs)); must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs));
......
...@@ -32,17 +32,17 @@ int write_object_data(char *file, void *data, size_t len) ...@@ -32,17 +32,17 @@ int write_object_data(char *file, void *data, size_t len)
git_file fd; git_file fd;
int ret; int ret;
if ((fd = gitfo_creat(file, S_IREAD | S_IWRITE)) < 0) if ((fd = p_creat(file, S_IREAD | S_IWRITE)) < 0)
return -1; return -1;
ret = gitfo_write(fd, data, len); ret = p_write(fd, data, len);
gitfo_close(fd); p_close(fd);
return ret; return ret;
} }
int write_object_files(const char *odb_dir, object_data *d) int write_object_files(const char *odb_dir, object_data *d)
{ {
if (gitfo_mkdir(odb_dir, 0755) < 0) { if (p_mkdir(odb_dir, 0755) < 0) {
int err = errno; int err = errno;
fprintf(stderr, "can't make directory \"%s\"", odb_dir); fprintf(stderr, "can't make directory \"%s\"", odb_dir);
if (err == EEXIST) if (err == EEXIST)
...@@ -51,7 +51,7 @@ int write_object_files(const char *odb_dir, object_data *d) ...@@ -51,7 +51,7 @@ int write_object_files(const char *odb_dir, object_data *d)
return -1; return -1;
} }
if ((gitfo_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) { if ((p_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) {
fprintf(stderr, "can't make object directory \"%s\"\n", d->dir); fprintf(stderr, "can't make object directory \"%s\"\n", d->dir);
return -1; return -1;
} }
...@@ -65,16 +65,16 @@ int write_object_files(const char *odb_dir, object_data *d) ...@@ -65,16 +65,16 @@ int write_object_files(const char *odb_dir, object_data *d)
int remove_object_files(const char *odb_dir, object_data *d) int remove_object_files(const char *odb_dir, object_data *d)
{ {
if (gitfo_unlink(d->file) < 0) { if (p_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file); fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1; return -1;
} }
if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) { if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove object directory \"%s\"\n", d->dir); fprintf(stderr, "can't remove object directory \"%s\"\n", d->dir);
return -1; return -1;
} }
if (gitfo_rmdir(odb_dir) < 0) { if (p_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir); fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir);
return -1; return -1;
} }
...@@ -104,14 +104,14 @@ int remove_loose_object(const char *repository_folder, git_object *object) ...@@ -104,14 +104,14 @@ int remove_loose_object(const char *repository_folder, git_object *object)
ptr += GIT_OID_HEXSZ + 1; ptr += GIT_OID_HEXSZ + 1;
*ptr = 0; *ptr = 0;
if (gitfo_unlink(full_path) < 0) { if (p_unlink(full_path) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", full_path); fprintf(stderr, "can't delete object file \"%s\"\n", full_path);
return -1; return -1;
} }
*top_folder = 0; *top_folder = 0;
if ((gitfo_rmdir(full_path) < 0) && (errno != ENOTEMPTY)) { if ((p_rmdir(full_path) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove object directory \"%s\"\n", full_path); fprintf(stderr, "can't remove object directory \"%s\"\n", full_path);
return -1; return -1;
} }
...@@ -134,44 +134,44 @@ int cmp_objects(git_rawobj *o, object_data *d) ...@@ -134,44 +134,44 @@ int cmp_objects(git_rawobj *o, object_data *d)
int copy_file(const char *src, const char *dst) int copy_file(const char *src, const char *dst)
{ {
gitfo_buf source_buf; git_fbuffer source_buf;
git_file dst_fd; git_file dst_fd;
int error = GIT_ERROR; int error = GIT_ERROR;
if (gitfo_read_file(&source_buf, src) < GIT_SUCCESS) if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
dst_fd = gitfo_creat_force(dst, 0644); dst_fd = git_futils_creat_withpath(dst, 0644);
if (dst_fd < 0) if (dst_fd < 0)
goto cleanup; goto cleanup;
error = gitfo_write(dst_fd, source_buf.data, source_buf.len); error = p_write(dst_fd, source_buf.data, source_buf.len);
cleanup: cleanup:
gitfo_free_buf(&source_buf); git_futils_freebuffer(&source_buf);
gitfo_close(dst_fd); p_close(dst_fd);
return error; return error;
} }
int cmp_files(const char *a, const char *b) int cmp_files(const char *a, const char *b)
{ {
gitfo_buf buf_a, buf_b; git_fbuffer buf_a, buf_b;
int error = GIT_ERROR; int error = GIT_ERROR;
if (gitfo_read_file(&buf_a, a) < GIT_SUCCESS) if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS)
return GIT_ERROR; return GIT_ERROR;
if (gitfo_read_file(&buf_b, b) < GIT_SUCCESS) { if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) {
gitfo_free_buf(&buf_a); git_futils_freebuffer(&buf_a);
return GIT_ERROR; return GIT_ERROR;
} }
if (buf_a.len == buf_b.len && !memcmp(buf_a.data, buf_b.data, buf_a.len)) if (buf_a.len == buf_b.len && !memcmp(buf_a.data, buf_b.data, buf_a.len))
error = GIT_SUCCESS; error = GIT_SUCCESS;
gitfo_free_buf(&buf_a); git_futils_freebuffer(&buf_a);
gitfo_free_buf(&buf_b); git_futils_freebuffer(&buf_b);
return error; return error;
} }
...@@ -182,11 +182,11 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path) ...@@ -182,11 +182,11 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path)
GIT_UNUSED_ARG(nil); GIT_UNUSED_ARG(nil);
error = gitfo_isdir(path); error = git_futils_isdir(path);
if (error == GIT_SUCCESS) { if (error == GIT_SUCCESS) {
size_t root_size = strlen(path); size_t root_size = strlen(path);
error = gitfo_dirent(path, GIT_PATH_MAX, remove_filesystem_element_recurs, NULL); error = git_futils_direach(path, GIT_PATH_MAX, remove_filesystem_element_recurs, NULL);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return error; return error;
...@@ -194,7 +194,7 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path) ...@@ -194,7 +194,7 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path)
return rmdir(path); return rmdir(path);
} }
return gitfo_unlink(path); return p_unlink(path);
} }
int rmdir_recurs(const char *directory_path) int rmdir_recurs(const char *directory_path)
...@@ -214,10 +214,10 @@ static int copy_filesystem_element_recurs(void *_data, char *source) ...@@ -214,10 +214,10 @@ static int copy_filesystem_element_recurs(void *_data, char *source)
copydir_data *data = (copydir_data *)_data; copydir_data *data = (copydir_data *)_data;
data->dst[data->dst_len] = 0; data->dst[data->dst_len] = 0;
git__joinpath(data->dst, data->dst, source + data->src_len); git_path_join(data->dst, data->dst, source + data->src_len);
if (gitfo_isdir(source) == GIT_SUCCESS) if (git_futils_isdir(source) == GIT_SUCCESS)
return gitfo_dirent(source, GIT_PATH_MAX, copy_filesystem_element_recurs, _data); return git_futils_direach(source, GIT_PATH_MAX, copy_filesystem_element_recurs, _data);
return copy_file(source, data->dst); return copy_file(source, data->dst);
} }
...@@ -229,13 +229,14 @@ int copydir_recurs(const char *source_directory_path, const char *destination_di ...@@ -229,13 +229,14 @@ int copydir_recurs(const char *source_directory_path, const char *destination_di
copydir_data data; copydir_data data;
/* Source has to exist, Destination hast to _not_ exist */ /* Source has to exist, Destination hast to _not_ exist */
if (gitfo_isdir(source_directory_path) || !gitfo_isdir(destination_directory_path)) if (git_futils_isdir(source_directory_path) != GIT_SUCCESS ||
git_futils_isdir(destination_directory_path) == GIT_SUCCESS)
return GIT_EINVALIDPATH; return GIT_EINVALIDPATH;
git__joinpath(source_buffer, source_directory_path, ""); git_path_join(source_buffer, source_directory_path, "");
data.src_len = strlen(source_buffer); data.src_len = strlen(source_buffer);
git__joinpath(dest_buffer, destination_directory_path, ""); git_path_join(dest_buffer, destination_directory_path, "");
data.dst = dest_buffer; data.dst = dest_buffer;
data.dst_len = strlen(dest_buffer); data.dst_len = strlen(dest_buffer);
...@@ -262,14 +263,14 @@ static int remove_placeholders_recurs(void *filename, char *path) ...@@ -262,14 +263,14 @@ static int remove_placeholders_recurs(void *filename, char *path)
char passed_filename[GIT_PATH_MAX]; char passed_filename[GIT_PATH_MAX];
char *data = (char *)filename; char *data = (char *)filename;
if (!gitfo_isdir(path)) if (!git_futils_isdir(path))
return gitfo_dirent(path, GIT_PATH_MAX, remove_placeholders_recurs, data); return git_futils_direach(path, GIT_PATH_MAX, remove_placeholders_recurs, data);
if (git__basename_r(passed_filename, sizeof(passed_filename), path) < GIT_SUCCESS) if (git_path_basename_r(passed_filename, sizeof(passed_filename), path) < GIT_SUCCESS)
return GIT_EINVALIDPATH; return GIT_EINVALIDPATH;
if (!strcmp(data, passed_filename)) if (!strcmp(data, passed_filename))
return gitfo_unlink(path); return p_unlink(path);
return GIT_SUCCESS; return GIT_SUCCESS;
} }
...@@ -278,7 +279,7 @@ int remove_placeholders(char *directory_path, char *filename) ...@@ -278,7 +279,7 @@ int remove_placeholders(char *directory_path, char *filename)
{ {
char buffer[GIT_PATH_MAX]; char buffer[GIT_PATH_MAX];
if (gitfo_isdir(directory_path)) if (git_futils_isdir(directory_path))
return GIT_EINVALIDPATH; return GIT_EINVALIDPATH;
strcpy(buffer, directory_path); strcpy(buffer, directory_path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment