Branch Coverage

deps/libgit2/src/futils.c
Criterion Covered Total %
branch 156 444 35.1


line true false branch
34 0 187 if (git_buf_oom(path_out))
37 0 187 if ((fd = p_mkstemp(path_out->ptr)) < 0) {
43 0 187 if (p_chmod(path_out->ptr, (mode & ~mask))) {
56 0 0 if (git_futils_mkpath2file(path, dirmode) < 0)
60 0 0 if (fd < 0) {
73 0 316 if (fd < 0) {
91 0 144 if (git_futils_mkpath2file(path, dirmode) < 0)
100 0 2906 if (fd < 0)
108 0 0 if (fd < 0)
119 0 0 if (p_fstat(fd, &sb)) {
124 0 0 if (sb.st_size < 0) {
135 689 206 if (S_ISREG(raw_mode))
136 0 689 return S_IFREG | GIT_PERMS_CANONICAL(raw_mode);
137 0 206 else if (S_ISLNK(raw_mode))
139 0 206 else if (S_ISGITLINK(raw_mode))
141 206 0 else if (S_ISDIR(raw_mode))
154 0 2316 if (!git__is_ssizet(len)) {
159 0 2316 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);
0 2316 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);
160 0 2316 if (git_buf_grow(buf, alloc_len) < 0)
166 0 2316 if (read_size != (ssize_t)len) {
187 3411 0 assert(out && path && *path);
3411 0 assert(out && path && *path);
0 3411 assert(out && path && *path);
189 0 3411 if (updated != NULL)
192 1149 2262 if (p_stat(path, &st) < 0)
196 0 2262 if (S_ISDIR(st.st_mode)) {
201 0 2262 if (!git__is_sizet(st.st_size+1)) {
206 0 2262 if ((fd = git_futils_open_ro(path)) < 0)
209 0 2262 if (git_futils_readbuffer_fd(&buf, fd, (size_t)st.st_size) < 0) {
216 0 2262 if (checksum) {
217 0 0 if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
225 0 0 if (!git_oid__cmp(checksum, &checksum_new)) {
227 0 0 if (updated)
239 0 2262 if (updated != NULL)
258 21 122 if (!flags)
261 0 143 if ((flags & O_FSYNC) != 0)
266 0 143 if (!mode)
269 0 143 if ((fd = p_open(path, flags, mode)) < 0) {
274 0 143 if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
280 0 143 if (do_fsync && (error = p_fsync(fd)) < 0) {
0 0 if (do_fsync && (error = p_fsync(fd)) < 0) {
286 0 143 if ((error = p_close(fd)) < 0) {
291 0 143 if (do_fsync && (flags & O_CREAT))
0 0 if (do_fsync && (flags & O_CREAT))
299 0 0 if (git_futils_mkpath2file(to, dirmode) < 0)
302 0 0 if (p_rename(from, to) < 0) {
321 0 0 if (fd < 0)
324 0 0 if ((result = git_futils_filesize(&len, fd)) < 0)
327 0 0 if (!git__is_sizet(len)) {
352 0 304 if ((flags & GIT_MKDIR_EXCL) != 0) {
358 0 304 if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) ||
0 0 if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) ||
0 304 if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) ||
359 0 0 (S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) {
360 0 0 if (p_unlink(path) < 0) {
361 0 0 git_error_set(GIT_ERROR_OS, "failed to remove %s '%s'",
368 0 0 if (p_mkdir(path, mode) < 0) {
374 0 304 else if (S_ISLNK(st->st_mode)) {
378 0 0 if (p_stat(path, st) < 0) {
384 0 304 else if (!S_ISDIR(st->st_mode)) {
401 469 26 if (((terminal_path && (flags & GIT_MKDIR_CHMOD) != 0) ||
469 0 if (((terminal_path && (flags & GIT_MKDIR_CHMOD) != 0) ||
0 495 if (((terminal_path && (flags & GIT_MKDIR_CHMOD) != 0) ||
402 0 0 (flags & GIT_MKDIR_CHMOD_PATH) != 0) && st->st_mode != mode) {
406 0 0 if (p_chmod(path, mode) < 0) {
421 0 517 if (path->size == 0) {
427 0 517 if ((root_len = git_path_root(path->ptr)) < 0)
432 562 0 while (path->size > (size_t)root_len && path->ptr[path->size - 1] == '/')
45 517 while (path->size > (size_t)root_len && path->ptr[path->size - 1] == '/')
436 0 517 if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
440 460 57 if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
447 0 517 if (path->size <= (size_t)root_len)
465 282 0 if ((error = git_buf_puts(&make_path, path)) < 0 ||
282 0 if ((error = git_buf_puts(&make_path, path)) < 0 ||
466 282 0 (error = mkdir_canonicalize(&make_path, flags)) < 0 ||
467 282 0 (error = git_buf_puts(&parent_path, make_path.ptr)) < 0 ||
476 293 0 for (relative = make_path.ptr; parent_path.size; ) {
479 273 20 if (error == 0) {
481 0 20 } else if (errno != ENOENT) {
490 0 20 if ((len = git_path_dirname_r(&parent_path, parent_path.ptr)) < 0) {
495 0 20 assert(len);
503 0 20 if ((len == 1 && parent_path.ptr[0] == '.') ||
0 0 if ((len == 1 && parent_path.ptr[0] == '.') ||
0 20 if ((len == 1 && parent_path.ptr[0] == '.') ||
504 0 0 (len == 1 && parent_path.ptr[0] == '/') ||
0 20 (len == 1 && parent_path.ptr[0] == '/') ||
513 9 11 if ((flags & GIT_MKDIR_PATH) == 0)
520 268 14 if (depth == 0) {
523 268 0 if (!error)
535 14 0 error = git_futils_mkdir_relative(relative,
563 187 48 if (!opts)
567 0 235 if (git_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
570 235 0 if ((error = mkdir_canonicalize(&make_path, flags)) < 0 ||
235 0 if ((error = mkdir_canonicalize(&make_path, flags)) < 0 ||
575 9 226 if ((flags & GIT_MKDIR_PATH) == 0)
580 0 235 if (root < min_root_len)
582 249 0 while (root >= 0 && make_path.ptr[root] == '/')
14 235 while (root >= 0 && make_path.ptr[root] == '/')
586 0 235 if (root > (ssize_t)make_path.size)
588 0 235 if (root < 0)
592 227 235 for (tail = &make_path.ptr[root]; *tail; *tail = lastch) {
596 26 227 while (*tail == '/')
598 729 201 while (*tail && *tail != '/')
703 26 while (*tail && *tail != '/')
606 0 227 if (opts->dir_map && git_strmap_exists(opts->dir_map, make_path.ptr))
0 0 if (opts->dir_map && git_strmap_exists(opts->dir_map, make_path.ptr))
613 191 36 if (p_lstat(make_path.ptr, &st) < 0) {
614 191 0 if (mkdir_attempted || errno != ENOENT) {
0 191 if (mkdir_attempted || errno != ENOENT) {
623 0 191 if (p_mkdir(make_path.ptr, mode) < 0) {
624 0 0 if (errno == EEXIST)
631 0 36 if ((error = mkdir_validate_dir(
637 0 227 if ((error = mkdir_validate_mode(
641 0 227 if (opts->dir_map && opts->pool) {
0 0 if (opts->dir_map && opts->pool) {
645 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, make_path.size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, make_path.size, 1);
647 0 0 GIT_ERROR_CHECK_ALLOC(cache_path);
651 0 0 if ((error = git_strmap_set(opts->dir_map, cache_path, cache_path)) < 0)
659 200 35 if ((flags & GIT_MKDIR_VERIFY_DIR) != 0 &&
34 166 if ((flags & GIT_MKDIR_VERIFY_DIR) != 0 &&
663 34 0 if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) {
0 34 if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) {
686 0 0 if (filemsg)
700 0 0 while (error == GIT_ENOTFOUND) {
703 0 0 if (!path->size || git__prefixcmp(path->ptr, ceiling) != 0)
0 0 if (!path->size || git__prefixcmp(path->ptr, ceiling) != 0)
705 0 0 else if (p_lstat_posixly(path->ptr, &st) == 0) {
706 0 0 if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
0 0 if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
708 0 0 else if (!S_ISDIR(st.st_mode))
710 0 0 } else if (errno != ENOTDIR)
714 0 0 if (error)
726 0 182 if (data->depth > FUTILS_MAX_DEPTH)
730 39 143 else if ((error = p_lstat_posixly(path->ptr, &st)) < 0) {
731 39 0 if (errno == ENOENT)
733 0 0 else if (errno == ENOTDIR) {
735 0 0 if ((data->flags & GIT_RMDIR_REMOVE_BLOCKERS) != 0)
745 12 131 else if (S_ISDIR(st.st_mode)) {
752 0 12 if (error < 0)
755 12 0 if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0)
0 12 if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0)
758 0 12 if ((error = p_rmdir(path->ptr)) < 0) {
760 0 0 (errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
0 0 (errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
767 55 76 else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) {
768 0 55 if (p_unlink(path->ptr) < 0)
772 0 76 else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0)
783 26 30 if (strlen(path) <= data->baselen)
786 26 4 else if (p_rmdir(path) < 0) {
789 0 26 if (en == ENOENT || en == ENOTDIR) {
0 0 if (en == ENOENT || en == ENOTDIR) {
791 0 0 } else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 &&
0 0 } else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 &&
794 0 0 } else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
0 0 } else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
0 0 } else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
812 0 145 if (git_path_join_unrooted(&fullpath, path, base, NULL) < 0)
816 134 11 data.base = base ? base : "";
817 134 11 data.baselen = base ? strlen(base) : 0;
823 145 0 if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
26 119 if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
827 26 119 if (error == GIT_ITEROVER) {
841 0 0 if (fd >= 0) {
854 0 0 while (!error && (len = p_read(ifd, buffer, sizeof(buffer))) > 0)
0 0 while (!error && (len = p_read(ifd, buffer, sizeof(buffer))) > 0)
860 0 0 if (len < 0) {
865 0 0 if (error < 0)
868 0 0 if (close_fd_when_done) {
880 0 0 if ((ifd = git_futils_open_ro(from)) < 0)
883 0 0 if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) {
896 0 286 times[0].tv_sec = times[1].tv_sec = when ? *when : time(NULL);
901 163 123 return (ret < 0) ? git_path_set_error(errno, path, "touch") : 0;
911 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, link_size, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, link_size, 1);
913 0 0 GIT_ERROR_CHECK_ALLOC(link_data);
916 0 0 if (read_len != (ssize_t)link_size) {
923 0 0 if (p_symlink(link_data, to) < 0) {
950 0 0 if ((info->flags & GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT) == 0) {
951 0 0 error = git_futils_mkdir(
959 0 0 if (!error)
978 0 0 if ((error = git_buf_joinpath(
982 0 0 if (!(error = git_path_lstat(info->to.ptr, &to_st)))
984 0 0 else if (error != GIT_ENOTFOUND)
991 0 0 if ((error = git_path_lstat(from->ptr, &from_st)) < 0)
994 0 0 if (S_ISDIR(from_st.st_mode)) {
998 0 0 if ((info->flags & GIT_CPDIR_CHMOD_DIRS) == 0)
1002 0 0 if (!exists && (info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) != 0)
0 0 if (!exists && (info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) != 0)
1006 0 0 if (!error && (!exists || S_ISDIR(to_st.st_mode)))
0 0 if (!error && (!exists || S_ISDIR(to_st.st_mode)))
0 0 if (!error && (!exists || S_ISDIR(to_st.st_mode)))
1009 0 0 if (oldmode != 0)
1015 0 0 if (exists) {
1016 0 0 if ((info->flags & GIT_CPDIR_OVERWRITE) == 0)
1019 0 0 if (p_unlink(info->to.ptr) < 0) {
1027 0 0 if (!S_ISREG(from_st.st_mode) &&
0 0 if (!S_ISREG(from_st.st_mode) &&
1028 0 0 (!S_ISLNK(from_st.st_mode) ||
1033 0 0 if ((info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0 &&
0 0 if ((info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0 &&
1038 0 0 if (info->flags & GIT_CPDIR_LINK_FILES) {
1039 0 0 if ((error = p_link(from->ptr, info->to.ptr)) < 0)
1041 0 0 } else if (S_ISLNK(from_st.st_mode)) {
1046 0 0 if ((info->flags & GIT_CPDIR_SIMPLE_TO_MODE) != 0)
1047 0 0 usemode = GIT_PERMS_FOR_WRITE(usemode);
1065 0 0 if (git_buf_joinpath(&path, from, "") < 0) /* ensure trailing slash */
1076 0 0 if ((flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0) {
1081 0 0 if ((flags & GIT_CPDIR_CHMOD_DIRS) != 0)
1085 0 0 info.mkdir_flags =
1103 0 2672 if (stamp == NULL)
1106 1257 1415 if (p_stat(path, &st) < 0)
1109 1382 33 if (stamp->mtime.tv_sec == st.st_mtime &&
1330 52 if (stamp->mtime.tv_sec == st.st_mtime &&
1113 1289 41 stamp->size == (uint64_t)st.st_size &&
1130 0 82 assert(target);
1132 11 71 if (source)
1142 102 0 if (st) {
1164 0 0 if ((fd = p_open(path, O_RDONLY)) < 0) {
1169 0 0 if ((error = p_fsync(fd)) < 0)
1182 0 0 if ((parent = git_path_dirname(path)) == NULL)