本文整理汇总了C++中p_stat函数的典型用法代码示例。如果您正苦于以下问题:C++ p_stat函数的具体用法?C++ p_stat怎么用?C++ p_stat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了p_stat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: test_checkout_index__options_dir_modes
void test_checkout_index__options_dir_modes(void)
{
#ifndef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
git_oid oid;
git_commit *commit;
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
reset_index_to_treeish((git_object *)commit);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
opts.dir_mode = 0701;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_git_pass(p_stat("./testrepo/a", &st));
cl_assert_equal_i(st.st_mode & 0777, 0701);
/* File-mode test, since we're on the 'dir' branch */
cl_git_pass(p_stat("./testrepo/a/b.txt", &st));
cl_assert_equal_i(st.st_mode & 0777, 0755);
git_commit_free(commit);
#endif
}
开发者ID:duralog,项目名称:node-sencillo,代码行数:28,代码来源:index.c
示例2: test_write_object_permission
void test_write_object_permission(
mode_t dir_mode, mode_t file_mode,
mode_t expected_dir_mode, mode_t expected_file_mode)
{
git_odb *odb;
git_odb_backend *backend;
git_oid oid;
struct stat statbuf;
mode_t mask, os_mask;
/* Windows does not return group/user bits from stat,
* files are never executable.
*/
#ifdef GIT_WIN32
os_mask = 0600;
#else
os_mask = 0777;
#endif
mask = p_umask(0);
p_umask(mask);
cl_git_pass(git_odb_new(&odb));
cl_git_pass(git_odb_backend_loose(&backend, "test-objects", -1, 0, dir_mode, file_mode));
cl_git_pass(git_odb_add_backend(odb, backend, 1));
cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB));
cl_git_pass(p_stat("test-objects/67", &statbuf));
cl_assert_equal_i(statbuf.st_mode & os_mask, (expected_dir_mode & ~mask) & os_mask);
cl_git_pass(p_stat("test-objects/67/b808feb36201507a77f85e6d898f0a2836e4a5", &statbuf));
cl_assert_equal_i(statbuf.st_mode & os_mask, (expected_file_mode & ~mask) & os_mask);
git_odb_free(odb);
}
开发者ID:CodeSmithyIDE,项目名称:libgit2,代码行数:35,代码来源:loose.c
示例3: test_checkout_index__options_dir_modes
void test_checkout_index__options_dir_modes(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
struct stat st;
git_oid oid;
git_commit *commit;
mode_t um;
if (!cl_is_chmod_supported())
return;
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
reset_index_to_treeish((git_object *)commit);
opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
opts.dir_mode = 0701;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
/* umask will influence actual directory creation mode */
(void)p_umask(um = p_umask(022));
cl_git_pass(p_stat("./testrepo/a", &st));
/* Haiku & Hurd use other mode bits, so we must mask them out */
cl_assert_equal_i_fmt(st.st_mode & (S_IFMT | 07777), (GIT_FILEMODE_TREE | 0701) & ~um, "%07o");
/* File-mode test, since we're on the 'dir' branch */
cl_git_pass(p_stat("./testrepo/a/b.txt", &st));
cl_assert_equal_i_fmt(st.st_mode & (S_IFMT | 07777), GIT_FILEMODE_BLOB_EXECUTABLE & ~um, "%07o");
git_commit_free(commit);
}
开发者ID:Angeldude,项目名称:sonic-pi,代码行数:34,代码来源:index.c
示例4: test_checkout_index__options_dir_modes
void test_checkout_index__options_dir_modes(void)
{
#ifndef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
git_oid oid;
git_commit *commit;
mode_t um;
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
reset_index_to_treeish((git_object *)commit);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
opts.dir_mode = 0701;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
/* umask will influence actual directory creation mode */
(void)p_umask(um = p_umask(022));
cl_git_pass(p_stat("./testrepo/a", &st));
cl_assert_equal_i_fmt(st.st_mode, (GIT_FILEMODE_TREE | 0701) & ~um, "%07o");
/* File-mode test, since we're on the 'dir' branch */
cl_git_pass(p_stat("./testrepo/a/b.txt", &st));
cl_assert_equal_i_fmt(st.st_mode, GIT_FILEMODE_BLOB_EXECUTABLE, "%07o");
git_commit_free(commit);
#endif
}
开发者ID:benqian,项目名称:repobuild,代码行数:32,代码来源:index.c
示例5: cl_toggle_filemode
bool cl_toggle_filemode(const char *filename)
{
struct stat st1, st2;
cl_must_pass(p_stat(filename, &st1));
cl_must_pass(p_chmod(filename, st1.st_mode ^ 0100));
cl_must_pass(p_stat(filename, &st2));
return (st1.st_mode != st2.st_mode);
}
开发者ID:0CV0,项目名称:libgit2,代码行数:10,代码来源:clar_libgit2.c
示例6: is_chmod_supported
static bool is_chmod_supported(const char *file_path)
{
struct stat st1, st2;
if (p_stat(file_path, &st1) < 0)
return false;
if (p_chmod(file_path, st1.st_mode ^ S_IXUSR) < 0)
return false;
if (p_stat(file_path, &st2) < 0)
return false;
return (st1.st_mode != st2.st_mode);
}
开发者ID:Darthholi,项目名称:WDX_GitCommander,代码行数:15,代码来源:repository.c
示例7: test_core_posix__utimes
void test_core_posix__utimes(void)
{
struct timeval times[2];
struct stat st;
time_t curtime;
int fd;
/* test p_utimes */
times[0].tv_sec = 1234567890;
times[0].tv_usec = 0;
times[1].tv_sec = 1234567890;
times[1].tv_usec = 0;
cl_git_mkfile("foo", "Dummy file.");
cl_must_pass(p_utimes("foo", times));
p_stat("foo", &st);
cl_assert_equal_i(1234567890, st.st_atime);
cl_assert_equal_i(1234567890, st.st_mtime);
/* test p_futimes */
times[0].tv_sec = 1414141414;
times[0].tv_usec = 0;
times[1].tv_sec = 1414141414;
times[1].tv_usec = 0;
cl_must_pass(fd = p_open("foo", O_RDWR));
cl_must_pass(p_futimes(fd, times));
p_close(fd);
p_stat("foo", &st);
cl_assert_equal_i(1414141414, st.st_atime);
cl_assert_equal_i(1414141414, st.st_mtime);
/* test p_utimes with current time, assume that
* it takes < 5 seconds to get the time...!
*/
cl_must_pass(p_utimes("foo", NULL));
curtime = time(NULL);
p_stat("foo", &st);
cl_assert((st.st_atime - curtime) < 5);
cl_assert((st.st_mtime - curtime) < 5);
p_unlink("foo");
}
开发者ID:DavidMolinari,项目名称:sonic-pi,代码行数:48,代码来源:posix.c
示例8: _isExecutable
static
int
_isExecutable(const char* path)
{
struct s_stat st;
return ((p_stat(path, &st) == 0) && (st.st_mode & _S_IEXEC));
}
开发者ID:talos-vulndev,项目名称:afl-cygwin,代码行数:7,代码来源:winapi.c
示例9: test_core_filebuf__umask
/* make sure git_filebuf_commit takes umask into account */
void test_core_filebuf__umask(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
char test[] = "test";
struct stat statbuf;
mode_t mask, os_mask;
#ifdef GIT_WIN32
os_mask = 0600;
#else
os_mask = 0777;
#endif
p_umask(mask = p_umask(0));
cl_assert(file.buffer == NULL);
cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
cl_assert(file.buffer != NULL);
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
cl_assert(file.buffer != NULL);
cl_git_pass(git_filebuf_commit(&file));
cl_assert(file.buffer == NULL);
cl_must_pass(p_stat("test", &statbuf));
cl_assert_equal_i(statbuf.st_mode & os_mask, (0666 & ~mask) & os_mask);
cl_must_pass(p_unlink(test));
}
开发者ID:structuresound,项目名称:libgit2,代码行数:31,代码来源:filebuf.c
示例10: hack_index
static void hack_index(char *files[])
{
char *filename;
struct stat statbuf;
git_buf path = GIT_BUF_INIT;
git_index_entry *entry;
size_t i;
/* Update the index to suggest that checkout placed these files on
* disk, keeping the object id but updating the cache, which will
* emulate a Git implementation's different filter.
*/
for (i = 0, filename = files[i]; filename; filename = files[++i]) {
git_buf_clear(&path);
cl_assert(entry = (git_index_entry *)
git_index_get_bypath(repo_index, filename, 0));
cl_git_pass(git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
cl_git_pass(p_stat(path.ptr, &statbuf));
entry->ctime.seconds = (git_time_t)statbuf.st_ctime;
entry->ctime.nanoseconds = 0;
entry->mtime.seconds = (git_time_t)statbuf.st_mtime;
entry->mtime.nanoseconds = 0;
entry->dev = statbuf.st_dev;
entry->ino = statbuf.st_ino;
entry->uid = statbuf.st_uid;
entry->gid = statbuf.st_gid;
entry->file_size = statbuf.st_size;
}
git_buf_free(&path);
}
开发者ID:1336,项目名称:libgit2,代码行数:34,代码来源:dirty.c
示例11: git_index_write
int git_index_write(git_index *index)
{
git_filebuf file;
struct stat indexst;
int error;
git_vector_sort(&index->entries);
if ((error = git_filebuf_open(&file, index->index_file_path, GIT_FILEBUF_HASH_CONTENTS)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write index");
if ((error = write_index(index, &file)) < GIT_SUCCESS) {
git_filebuf_cleanup(&file);
return git__rethrow(error, "Failed to write index");
}
if ((error = git_filebuf_commit(&file)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write index");
if (p_stat(index->index_file_path, &indexst) == 0) {
index->last_modified = indexst.st_mtime;
index->on_disk = 1;
}
return GIT_SUCCESS;
}
开发者ID:boyski,项目名称:libgit2,代码行数:26,代码来源:index.c
示例12: packfile_refresh_all
static int packfile_refresh_all(struct pack_backend *backend)
{
int error;
struct stat st;
if (backend->pack_folder == NULL)
return GIT_SUCCESS;
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");
if (st.st_mtime != backend->pack_folder_mtime) {
char path[GIT_PATH_MAX];
strcpy(path, backend->pack_folder);
/* reload all packs */
error = git_futils_direach(path, GIT_PATH_MAX, packfile_load__cb, (void *)backend);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to refresh packfiles");
git_vector_sort(&backend->packs);
backend->pack_folder_mtime = st.st_mtime;
}
return GIT_SUCCESS;
}
开发者ID:fatlotus,项目名称:nodegit,代码行数:26,代码来源:odb_pack.c
示例13: setup_race
static void setup_race(void)
{
git_buf path = GIT_BUF_INIT;
git_index *index;
git_index_entry *entry;
struct stat st;
/* Make sure we do have a timestamp */
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
cl_git_pass(git_index_write(index));
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
cl_git_mkfile(path.ptr, "A");
cl_git_pass(git_index_add_bypath(index, "A"));
cl_git_mkfile(path.ptr, "B");
cl_git_pass(git_index_write(index));
cl_git_mkfile(path.ptr, "");
cl_git_pass(p_stat(path.ptr, &st));
cl_assert(entry = (git_index_entry *)git_index_get_bypath(index, "A", 0));
/* force a race */
entry->mtime.seconds = (int32_t)st.st_mtime;
entry->mtime.nanoseconds = (int32_t)st.st_mtime_nsec;
git_buf_dispose(&path);
}
开发者ID:ethomson,项目名称:libgit2,代码行数:30,代码来源:racy.c
示例14: test_index_version__v4_uses_path_compression
void test_index_version__v4_uses_path_compression(void)
{
git_index_entry entry;
git_index *index;
char path[250], buf[1];
struct stat st;
char i, j;
memset(path, 'a', sizeof(path));
memset(buf, 'a', sizeof(buf));
memset(&entry, 0, sizeof(entry));
entry.path = path;
entry.mode = GIT_FILEMODE_BLOB;
g_repo = cl_git_sandbox_init("indexv4");
cl_git_pass(git_repository_index(&index, g_repo));
/* write 676 paths of 250 bytes length */
for (i = 'a'; i <= 'z'; i++) {
for (j = 'a'; j < 'z'; j++) {
path[ARRAY_SIZE(path) - 3] = i;
path[ARRAY_SIZE(path) - 2] = j;
path[ARRAY_SIZE(path) - 1] = '\0';
cl_git_pass(git_index_add_frombuffer(index, &entry, buf, sizeof(buf)));
}
}
cl_git_pass(git_index_write(index));
cl_git_pass(p_stat(git_index_path(index), &st));
/*
* Without path compression, the written paths would at
* least take
*
* (entries * pathlen) = len
* (676 * 250) = 169000
*
* bytes. As index v4 uses suffix-compression and our
* written paths only differ in the last two entries,
* this number will be much smaller, e.g.
*
* (1 * pathlen) + (675 * 2) = len
* 676 + 1350 = 2026
*
* bytes.
*
* Note that the above calculations do not include
* additional metadata of the index, e.g. OIDs or
* index extensions. Including those we get an index
* of approx. 200kB without compression and 40kB with
* compression. As this is a lot smaller than without
* compression, we can verify that path compression is
* used.
*/
cl_assert_(st.st_size < 75000, "path compression not enabled");
git_index_free(index);
}
开发者ID:Arhzi,项目名称:libgit2,代码行数:59,代码来源:version.c
示例15: git_futils_readbuffer_updated
int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mtime, int *updated)
{
git_file fd;
size_t len;
struct stat st;
unsigned char *buff;
assert(obj && path && *path);
if (updated != NULL)
*updated = 0;
if (p_stat(path, &st) < 0)
return git__throw(GIT_ENOTFOUND, "Failed to stat file %s", path);
if (S_ISDIR(st.st_mode))
return git__throw(GIT_ERROR, "Can't read a dir into a buffer");
/*
* If we were given a time, we only want to read the file if it
* has been modified.
*/
if (mtime != NULL && *mtime >= st.st_mtime)
return GIT_SUCCESS;
if (mtime != NULL)
*mtime = st.st_mtime;
if (!git__is_sizet(st.st_size+1))
return git__throw(GIT_ERROR, "Failed to read file `%s`. An error occured while calculating its size", path);
len = (size_t) st.st_size;
if ((fd = p_open(path, O_RDONLY)) < 0)
return git__throw(GIT_EOSERR, "Failed to open %s for reading", path);
if ((buff = git__malloc(len + 1)) == NULL) {
p_close(fd);
return GIT_ENOMEM;
}
if (p_read(fd, buff, len) < 0) {
p_close(fd);
free(buff);
return git__throw(GIT_ERROR, "Failed to read file `%s`", path);
}
buff[len] = '\0';
p_close(fd);
if (mtime != NULL)
*mtime = st.st_mtime;
if (updated != NULL)
*updated = 1;
obj->data = buff;
obj->len = len;
return GIT_SUCCESS;
}
开发者ID:fatlotus,项目名称:nodegit,代码行数:59,代码来源:fileops.c
示例16: try_create_file_with_nsec_timestamp
static bool try_create_file_with_nsec_timestamp(const char *path)
{
struct stat st;
int try;
/* retry a few times to avoid nanos *actually* equal 0 race condition */
for (try = 0; try < 3; try++) {
cl_git_mkfile(path, "This is hopefully a file with nanoseconds!");
cl_must_pass(p_stat(path, &st));
if (st.st_ctime_nsec && st.st_mtime_nsec)
return true;
}
return false;
}
/* try to determine if the underlying filesystem supports a resolution
* higher than a single second. (i'm looking at you, hfs+)
*/
static bool should_expect_nsecs(void)
{
git_buf nsec_path = GIT_BUF_INIT;
bool expect;
git_buf_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test");
expect = try_create_file_with_nsec_timestamp(nsec_path.ptr);
p_unlink(nsec_path.ptr);
git_buf_clear(&nsec_path);
return expect;
}
static bool has_nsecs(void)
{
const git_index_entry *entry;
size_t i;
bool has_nsecs = false;
for (i = 0; i < git_index_entrycount(repo_index); i++) {
entry = git_index_get_byindex(repo_index, i);
if (entry->ctime.nanoseconds || entry->mtime.nanoseconds) {
has_nsecs = true;
break;
}
}
return has_nsecs;
}
void test_index_nsec__has_nanos(void)
{
cl_assert_equal_b(true, has_nsecs());
}
开发者ID:Dipti126,项目名称:git,代码行数:59,代码来源:nsec.c
示例17: can_link
static bool can_link(const char *src, const char *dst, int link)
{
#ifdef GIT_WIN32
return false;
#else
struct stat st_src, st_dst;
if (!link)
return false;
if (p_stat(src, &st_src) < 0)
return false;
if (p_stat(dst, &st_dst) < 0)
return false;
return st_src.st_dev == st_dst.st_dev;
#endif
}
开发者ID:Kido-kid,项目名称:libgit2,代码行数:20,代码来源:clone.c
示例18: test_repo_init__detect_ignorecase
void test_repo_init__detect_ignorecase(void)
{
struct stat st;
bool found_without_match;
cl_git_write2file("testCAPS", "whatever\n", 0, O_CREAT | O_WRONLY, 0666);
found_without_match = (p_stat("Testcaps", &st) == 0);
cl_must_pass(p_unlink("testCAPS"));
assert_config_entry_on_init(
"core.ignorecase", found_without_match ? true : GIT_ENOTFOUND);
}
开发者ID:Arhzi,项目名称:libgit2,代码行数:12,代码来源:init.c
示例19: test_checkout_index__options_override_file_modes
void test_checkout_index__options_override_file_modes(void)
{
#ifndef GIT_WIN32
struct stat st;
g_opts.file_mode = 0700;
cl_git_pass(git_checkout_index(g_repo, &g_opts));
cl_git_pass(p_stat("./testrepo/new.txt", &st));
cl_assert_equal_i(st.st_mode & 0777, 0700);
#endif
}
开发者ID:ralpheav,项目名称:PM_GIT,代码行数:13,代码来源:index.c
示例20: test_checkout_index__options_override_file_modes
void test_checkout_index__options_override_file_modes(void)
{
#ifndef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
opts.file_mode = 0700;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_git_pass(p_stat("./testrepo/new.txt", &st));
cl_assert_equal_i(st.st_mode & 0777, 0700);
#endif
}
开发者ID:duralog,项目名称:node-sencillo,代码行数:15,代码来源:index.c
注:本文中的p_stat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论