Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161637277
D55248.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D55248.diff
View Options
diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c
--- a/usr.bin/diff/diffdir.c
+++ b/usr.bin/diff/diffdir.c
@@ -60,7 +60,8 @@
RB_GENERATE_STATIC(inodetree, inode, entry, inodecmp);
static int
-vscandir(struct inodetree *tree, const char *path, struct dirent ***dirp,
+vscandir(struct inodetree *tree, struct inode **inop,
+ const char *path, struct dirent ***dirp,
int (*selectf)(const struct dirent *),
int (*comparf)(const struct dirent **, const struct dirent **))
{
@@ -85,6 +86,7 @@
goto fail;
RB_INSERT(inodetree, tree, ino);
close(fd);
+ *inop = ino;
return (ret);
fail:
serrno = errno;
@@ -96,6 +98,13 @@
return (-1);
}
+static void
+leavedir(struct inodetree *tree, struct inode *ino)
+{
+ RB_REMOVE(inodetree, tree, ino);
+ free(ino);
+}
+
/*
* Diff directory traversal. Will be called recursively if -r was specified.
*/
@@ -104,6 +113,7 @@
{
struct dirent *dent1, **dp1, **edp1, **dirp1 = NULL;
struct dirent *dent2, **dp2, **edp2, **dirp2 = NULL;
+ struct inode *ino1 = NULL, *ino2 = NULL;
size_t dirlen1, dirlen2;
char path1[PATH_MAX], path2[PATH_MAX];
int pos;
@@ -131,7 +141,7 @@
* Get a list of entries in each directory, skipping "excluded" files
* and sorting alphabetically.
*/
- pos = vscandir(&v1, path1, &dirp1, selectfile, alphasort);
+ pos = vscandir(&v1, &ino1, path1, &dirp1, selectfile, alphasort);
if (pos == -1) {
if (errno == ENOENT && (Nflag || Pflag)) {
pos = 0;
@@ -143,7 +153,7 @@
dp1 = dirp1;
edp1 = dirp1 + pos;
- pos = vscandir(&v2, path2, &dirp2, selectfile, alphasort);
+ pos = vscandir(&v2, &ino2, path2, &dirp2, selectfile, alphasort);
if (pos == -1) {
if (errno == ENOENT && Nflag) {
pos = 0;
@@ -217,11 +227,15 @@
closem:
if (dirp1 != NULL) {
+ if (ino1 != NULL)
+ leavedir(&v1, ino1);
for (dp1 = dirp1; dp1 < edp1; dp1++)
free(*dp1);
free(dirp1);
}
if (dirp2 != NULL) {
+ if (ino2 != NULL)
+ leavedir(&v2, ino2);
for (dp2 = dirp2; dp2 < edp2; dp2++)
free(*dp2);
free(dirp2);
diff --git a/usr.bin/diff/tests/diff_test.sh b/usr.bin/diff/tests/diff_test.sh
--- a/usr.bin/diff/tests/diff_test.sh
+++ b/usr.bin/diff/tests/diff_test.sh
@@ -382,6 +382,11 @@
-e match:"a/foo/bar/up: Directory loop detected" \
-e match:"b/foo/bar/up: Directory loop detected" \
diff -r a b
+ atf_check rm [ab]/foo/bar/up
+ atf_check mkdir -p b/foo/bar
+ atf_check ln -s foo a/baz
+ atf_check ln -s foo b/baz
+ atf_check diff -r a b
}
bigc_head()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jul 6, 12:09 PM (7 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34755180
Default Alt Text
D55248.diff (2 KB)
Attached To
Mode
D55248: diff: Improve directory loop detection
Attached
Detach File
Event Timeline
Log In to Comment