@@ -148,6 +148,9 @@ handle_walk_ppath_rec(
if (rec->p_flags & PARENT_IS_ROOT)
return wpi->fn(wpi->mntpt, wpi->path, wpi->arg);
+ if (path_will_loop(wpi->path, rec->p_ino))
+ return 0;
+
ret = path_component_change(wpli->pc, rec->p_name,
strlen((char *)rec->p_name), rec->p_ino);
if (ret)
@@ -734,3 +734,19 @@ path_walk_components(
return 0;
}
+
+/* Will this path contain a loop if we add this inode? */
+bool
+path_will_loop(
+ const struct path_list *path_list,
+ uint64_t ino)
+{
+ struct path_component *pc;
+
+ list_for_each_entry(pc, &path_list->p_head, pc_list) {
+ if (pc->pc_ino == ino)
+ return true;
+ }
+
+ return false;
+}
@@ -83,4 +83,6 @@ typedef int (*path_walk_fn_t)(const char *name, uint64_t ino, void *arg);
int path_walk_components(const struct path_list *path, path_walk_fn_t fn,
void *arg);
+bool path_will_loop(const struct path_list *path, uint64_t ino);
+
#endif /* __LIBFROG_PATH_H__ */