int git_futils_creat_withpath(const char *path, int mode) { if (git_futils_mkpath2file(path) < GIT_SUCCESS) return git__throw(GIT_EOSERR, "Failed to create file %s", path); return p_creat(path, mode); }
static void file_create(const char *filename, const char *content) { int fd = p_creat(filename, 0644); cl_assert(fd >= 0); cl_must_pass(p_write(fd, content, strlen(content))); cl_must_pass(p_close(fd)); }
static void write_object_files(object_data *d) { int fd; if (p_mkdir(d->dir, GIT_OBJECT_DIR_MODE) < 0) cl_assert(errno == EEXIST); cl_assert((fd = p_creat(d->file, S_IREAD | S_IWRITE)) >= 0); cl_must_pass(p_write(fd, d->bytes, d->blen)); p_close(fd); }
int p_mkstemp(char *tmp_path) { #if defined(_MSC_VER) if (_mktemp_s(tmp_path, strlen(tmp_path) + 1) != 0) return GIT_EOSERR; #else if (_mktemp(tmp_path) == NULL) return GIT_EOSERR; #endif return p_creat(tmp_path, 0744); }
static int file_create(const char *filename, const char *content) { int fd; fd = p_creat(filename, 0666); if (fd == 0) return GIT_ERROR; if (p_write(fd, content, strlen(content)) != 0) return GIT_ERROR; if (p_close(fd) != 0) return GIT_ERROR; return GIT_SUCCESS; }
int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode) { int fd; if (git_futils_mkpath2file(path, dirmode) < 0) return -1; fd = p_creat(path, mode); if (fd < 0) { giterr_set(GITERR_OS, "Failed to create file '%s'", path); return -1; } return fd; }
void cl_git_mkfile(const char *filename, const char *content) { int fd; fd = p_creat(filename, 0666); cl_assert(fd != 0); if (content) { cl_must_pass(p_write(fd, content, strlen(content))); } else { cl_must_pass(p_write(fd, filename, strlen(filename))); cl_must_pass(p_write(fd, "\n", 1)); } cl_must_pass(p_close(fd)); }
/* make sure git_filebuf_open doesn't delete an existing lock */ void test_core_filebuf__0(void) { git_filebuf file = GIT_FILEBUF_INIT; int fd; char test[] = "test", testlock[] = "test.lock"; fd = p_creat(testlock, 0744); //-V536 cl_must_pass(fd); cl_must_pass(p_close(fd)); cl_git_fail(git_filebuf_open(&file, test, 0, 0666)); cl_assert(git_path_exists(testlock)); cl_must_pass(p_unlink(testlock)); }
static int create_empty_file(const char *path, mode_t mode) { int fd; if ((fd = p_creat(path, mode)) < 0) { giterr_set(GITERR_OS, "Error while creating '%s'", path); return -1; } if (p_close(fd) < 0) { giterr_set(GITERR_OS, "Error while closing '%s'", path); return -1; } return 0; }
/* make sure git_filebuf_open doesn't delete an existing lock */ void test_core_filebuf__0(void) { git_filebuf file; int fd; char test[] = "test", testlock[] = "test.lock"; fd = p_creat(testlock, 0744); cl_must_pass(fd); cl_must_pass(p_close(fd)); cl_git_fail(git_filebuf_open(&file, test, 0)); cl_git_pass(git_futils_exists(testlock)); cl_must_pass(p_unlink(testlock)); }
/* make sure GIT_FILEBUF_APPEND works as expected */ void test_core_filebuf__1(void) { git_filebuf file; int fd; char test[] = "test"; fd = p_creat(test, 0644); cl_must_pass(fd); cl_must_pass(p_write(fd, "libgit2 rocks\n", 14)); cl_must_pass(p_close(fd)); cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND)); cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); cl_git_pass(git_filebuf_commit(&file)); cl_must_pass(p_unlink(test)); }
#include "test_lib.h" #include "test_helpers.h" #include "fileops.h" #include "git2/status.h" static const char *test_blob_oid = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"; #define STATUS_WORKDIR_FOLDER TEST_RESOURCES "/status/" #define STATUS_REPOSITORY_TEMP_FOLDER TEMP_REPO_FOLDER ".gitted/" BEGIN_TEST(file0, "test retrieving OID from a file apart from the ODB") git_oid expected_id, actual_id; char filename[] = "new_file"; int fd; fd = p_creat(filename, 0644); must_pass(fd); must_pass(p_write(fd, "new_file\n", 9)); must_pass(p_close(fd)); must_pass(git_odb_hashfile(&actual_id, filename, GIT_OBJ_BLOB)); must_pass(git_oid_fromstr(&expected_id, test_blob_oid)); must_be_true(git_oid_cmp(&expected_id, &actual_id) == 0); must_pass(p_unlink(filename)); END_TEST static const char *entry_paths[] = { "current_file", "file_deleted",