/** * check if any dir or file within path is hidden */ int path_hidden(const char *path, int branch) { DBG("%s\n", path); if (!uopt.cow_enabled) RETURN(false); char whiteoutpath[PATHLEN_MAX]; if (BUILD_PATH(whiteoutpath, uopt.branches[branch].path, METADIR, path)) RETURN(false); // -1 as we MUST not end on the next path element char *walk = whiteoutpath + uopt.branches[branch].path_len + strlen(METADIR) - 1; // first slashes, e.g. we have path = /dir1/dir2/, will set walk = dir1/dir2/ while (*walk == '/') walk++; do { // walk over the directory name, walk will now be /dir2 while (*walk != '\0' && *walk != '/') walk++; // +1 due to \0, which gets added automatically char p[PATHLEN_MAX]; // walk - path = strlen(/dir1) snprintf(p, (walk - whiteoutpath) + 1, "%s", whiteoutpath); int res = filedir_hidden(p); if (res) RETURN(res); // path is hidden or error // as above the do loop, walk over the next slashes, walk = dir2/ while (*walk == '/') walk++; } while (*walk != '\0'); RETURN(0); }
/** * check if any dir or file within path is hidden */ bool path_hidden(const char *path, int branch) { if (!uopt.cow_enabled) return false; char whiteoutpath[PATHLEN_MAX]; if (BUILD_PATH(whiteoutpath, uopt.roots[branch].path, METADIR, path)) { syslog (LOG_WARNING, "%s(): Path too long\n", __func__); return false; } char *walk = whiteoutpath; // first slashes, e.g. we have path = /dir1/dir2/, will set walk = dir1/dir2/ while (*walk != '\0' && *walk == '/') walk++; bool first = true; do { // walk over the directory name, walk will now be /dir2 while (*walk != '\0' && *walk != '/') walk++; if (first) { // first dir in path is our branch, no need to check if it is hidden first = false; continue; } // +1 due to \0, which gets added automatically char p[PATHLEN_MAX]; snprintf(p, (walk - whiteoutpath) + 1, "%s", whiteoutpath); // walk - path = strlen(/dir1) bool res = filedir_hidden(p); if (res) return res; // path is hidden // as above the do loop, walk over the next slashes, walk = dir2/ while (*walk != '\0' && *walk == '/') walk++; } while (*walk != '\0'); return 0; }