예제 #1
0
파일: fileops.c 프로젝트: rue/libgit2
int gitfo_isdir(const char *path)
{
	struct stat st;
	int len, stat_error;

	if (!path)
		return GIT_ENOTFOUND;

	len = strlen(path);

	/* win32: stat path for folders cannot end in a slash */
	if (path[len - 1] == '/') {
		char *path_fixed = NULL;
		path_fixed = git__strdup(path);
		path_fixed[len - 1] = 0;
		stat_error = gitfo_stat(path_fixed, &st);
		free(path_fixed);
	} else {
		stat_error = gitfo_stat(path, &st);
	}

	if (stat_error < GIT_SUCCESS)
		return GIT_ENOTFOUND;

	if (!S_ISDIR(st.st_mode))
		return GIT_ENOTFOUND;

	return GIT_SUCCESS;
}
예제 #2
0
파일: index.c 프로젝트: hef/libgit2
int git_index_write(git_index *index)
{
	git_filelock file;
	struct stat indexst;

	if (!index->sorted)
		git_index__sort(index);

	if (git_filelock_init(&file, index->index_file_path) < 0)
		return GIT_EFLOCKFAIL;

	if (git_filelock_lock(&file, 0) < 0)
		return GIT_EFLOCKFAIL;

	if (git_index__write(index, &file) < 0) {
		git_filelock_unlock(&file);
		return GIT_EOSERR;
	}

	if (git_filelock_commit(&file) < 0)
		return GIT_EFLOCKFAIL;

	if (gitfo_stat(index->index_file_path, &indexst) == 0) {
		index->last_modified = indexst.st_mtime;
		index->on_disk = 1;
	}

	return 0;
}
예제 #3
0
파일: index.c 프로젝트: hef/libgit2
int git_index_add(git_index *index, const char *rel_path, int stage)
{
	git_index_entry entry;
	char full_path[GIT_PATH_MAX];
	struct stat st;
	int error;

	if (index->repository == NULL)
		return GIT_EBAREINDEX;

	strcpy(full_path, index->repository->path_workdir);
	strcat(full_path, rel_path);

	if (gitfo_exists(full_path) < 0)
		return GIT_ENOTFOUND;

	if (gitfo_stat(full_path, &st) < 0)
		return GIT_EOSERR;

	if (stage < 0 || stage > 3)
		return GIT_ERROR;

	memset(&entry, 0x0, sizeof(git_index_entry));

	entry.ctime.seconds = st.st_ctime;
	entry.mtime.seconds = st.st_mtime;
	/* entry.mtime.nanoseconds = st.st_mtimensec; */
	/* entry.ctime.nanoseconds = st.st_ctimensec; */
	entry.dev= st.st_rdev;
	entry.ino = st.st_ino;
	entry.mode = st.st_mode;
	entry.uid = st.st_uid;
	entry.gid = st.st_gid;
	entry.file_size = st.st_size;

	/* write the blob to disk and get the oid */
	if ((error = git_blob_writefile(&entry.oid, index->repository, full_path)) < 0)
		return error;

	entry.flags |= (stage << GIT_IDXENTRY_STAGESHIFT);
	entry.path = (char *)rel_path; /* do not duplicate; index_insert already does this */

	return git_index_insert(index, &entry);
}
예제 #4
0
파일: odb_pack.c 프로젝트: LuaDist/libgit2
static int pack_stat(git_pack *p)
{
	char pb[GIT_PATH_MAX];
	struct stat sb;

	if (git__fmt(pb, sizeof(pb), "%s/pack/%s.pack",
			p->backend->objects_dir,
			p->pack_name) < 0)
		return GIT_ERROR;

	if (gitfo_stat(pb, &sb) || !S_ISREG(sb.st_mode))
		return GIT_ERROR;

	if (sb.st_size < (3 * 4 + GIT_OID_RAWSZ))
		return GIT_ERROR;

	p->pack_size = sb.st_size;
	p->pack_mtime = sb.st_mtime;

	return GIT_SUCCESS;
}
예제 #5
0
파일: index.c 프로젝트: hef/libgit2
int git_index_read(git_index *index)
{
	struct stat indexst;
	int error = 0;

	assert(index->index_file_path);

	if (!index->on_disk || gitfo_exists(index->index_file_path) < 0) {
		git_index_clear(index);
		index->on_disk = 0;
		return 0;
	}

	if (gitfo_stat(index->index_file_path, &indexst) < 0)
		return GIT_EOSERR;

	if (!S_ISREG(indexst.st_mode))
		return GIT_ENOTFOUND;

	if (indexst.st_mtime != index->last_modified) {

		gitfo_buf buffer;

		if (gitfo_read_file(&buffer, index->index_file_path) < 0)
			return GIT_EOSERR;

		git_index_clear(index);
		error = git_index__parse(index, buffer.data, buffer.len);

		if (error == 0)
			index->last_modified = indexst.st_mtime;

		gitfo_free_buf(&buffer);
	}

	return error;
}