[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: (followup) Re: [despammed] Best way to recursive folders?
From:       Esben Mose Hansen <esben () despammed ! com>
Date:       2003-05-04 17:56:54
[Download RAW message or body]

On Sunday 04 May 2003 19:01, Jonathan Belson wrote:
> Hiya
>
> >>>
> >>>stack<Directories> dirs_to_be_processed;
> >>>do {
> >>>	for each file in diretory{
> >>>		if (file is a directory)
> >>>			dirs_to_be_processed.push(file);
> >>>		processFile(file);
> >>>	}
		// forgot a couple of obvius lines
		directory = dirs_to_be_processed.top();
		dirs_to_be_processed.pop();
> >>>} while (!.stack.empty())
>
> Isn't this code going to fail if the current directory has a link to
> a parent directory?  GNU grep with the '-r' option keeps track of
> the inode device and number for each file to detect recursive loops.
> See grep.c/grepdir() for the code in question.

Well, yeah, you're right of course. Forgot about symlinks... The above trick 
is for trees, really. It wouldn't be too hard to mend, though. When popping 
from the the stack, insert the inode into a set or hash. Keep popping until 
the insert succeeds.

This should turn the (directed) graph into a tree by ignoring all paths that 
lead to a previously encountered node.

Presumably, grep.c/grepdir() does something similar, but I don't have the code 
handy :)

regards, Esben


 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic