Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Advice for filesystem operations under Zsh

On Dec 2,  6:11pm, DervishD wrote:
}     Hello all :))

Hello, Raúl ...

}     The file list is stored in an array parameter, and in order to
} avoid reading from disk, the check is performed reading every 'list
} file' and comparing its contents (lines that are filenames) against
} the entire array

I don't see what disk read you're avoiding by this, but it probably
isn't important.

} deleting the corresponding entry if found. That
} way, at the end of iterations, the array contains all 'orphan' files.

When to delete an entry will depend on what else you need to do with
each entry, of course.

} [...] I want to extend the
} shell function so that, in one run, it outputs:
}     - Orphan files in file descriptor 3
}     - Dangling symlinks in file descriptor 4
}     - Setuid binaries in file descriptor 5
}     - Duplicate files in file descriptor 6
}     - Empty directories in file descriptor 7
}     - etc...

I'm not precisely sure what you mean by "duplicate files".  Names that
appear in the array more than once?  Or files with different names but
identical contents?  Or names that appear in more than one of the "list
files"?  Or ...?

}     Under Zsh is pretty easy to find all dangling symlinks
} (**/*(@-)), setuid files (**/*(s)), etc... and I can do all that in
} just one travel through the filesystem, since glob qualifiers work
} too with filenames withouth globbing characters.

I'm not following the order of operations here, probably because I have
no idea what "FSlint" is or how it works.  Do you want to create the
array of file names by scanning the file system, or do you already have
the names and now you want to learn things about those specific files?

} My problems are:
}     - finding dupes. I've tried to use 'I' subscript flag, but this
} only return all matching keys in an associative array, not in normal
} ones. The only solution seems to be deleting the match and search
} again...

This sounds like you want to find duplicate entries in the array.
Something like this:

    for element in $array
      if [[ "${${(@M)array:#$element}}" = $element ]]
	print $element is unique
	print $element is a duplicate

}     - finding empty directories.

We went over this once before, did we not?  However, the best approach
in this instance may depend on whether you're scanning the filesystem
anyway, or whether you are testing names obtained some other way.

}     - doing all that in one run of the array. Since the 'orphans'
} check destroys the contents of the array, I need to dupe it, or
} convert it to a associative array

Or just check for orphans last of anything, so that you don't need
the elements for other tests any more?

} I cannot find a solution for empty files.

Empty files wasn't on the list above, but isn't it **/*(L0)?

Messages sorted by: Reverse Date, Date, Thread, Author