/** * Find a writable root. If file does not exist, we check for * the parent directory. **/ int find_rw_root_cutlast(const char *path) { int root = find_rw_root_cow(path); if (root < 0 && errno == ENOENT) { // So path does not exist, now again, but with dirname only char *dname = u_dirname(path); int root_rorw = find_rorw_root(dname); free(dname); // nothing found if (root_rorw < 0) return -1; // the returned root is writable, good! if (uopt.roots[root_rorw].rw) return root_rorw; // cow is disabled, return whatever was found if (!uopt.cow_enabled) return root_rorw; int root_rw = find_lowest_rw_root(root_rorw); dname = u_dirname(path); int res = path_create(dname, root_rorw, root_rw); free(dname); // creating the path failed if (res) return -1; return root_rw; } return root; }
int main(int argc, char *argv[]) { const char *prog_name = NULL; Ustr *s1 = USTR_NULL; Ustr *s2 = USTR_NULL; if (!argc) exit (EXIT_FAILURE); if ((prog_name = strrchr(argv[0], '/'))) ++prog_name; else prog_name = argv[0]; if (argc != 2) die(prog_name, "missing operand"); if (!(s1 = ustr_dup_cstr(argv[1]))) die(prog_name, strerror(errno)); if (!(s2 = u_dirname(s1))) die(prog_name, strerror(errno)); ustr_free(s1); if (!ustr_io_putfileline(&s2, stderr)) die(prog_name, strerror(errno)); USTR_CNTL_MALLOC_CHECK_END(); exit (EXIT_SUCCESS); }
/** * Same as path_create(), but ignore the last segment in path, * i.e. it might be a filename. */ int path_create_cutlast(const char *path, int nbranch_ro, int nbranch_rw) { DBG_IN(); char *dname = u_dirname(path); if (dname == NULL) return -ENOMEM; int ret = path_create(dname, nbranch_ro, nbranch_rw); free(dname); return ret; }
/** * Same as path_create(), but ignore the last segment in path, * i.e. it might be a filename. */ int path_create_cutlast(const char *path, int nbranch_ro, int nbranch_rw) { DBG("%s\n", path); char *dname = u_dirname(path); if (dname == NULL) RETURN(-ENOMEM); int ret = path_create(dname, nbranch_ro, nbranch_rw); free(dname); RETURN(ret); }