Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

Cleanup Perl script should not delete a directory that is symlinked to

A cleanup Perl script running periodically deletes old log files, and if the folder is empty, it deletes the folder as well. Unfortunately, there is one exception: it should not delete a directory that is symlinked to.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's no way to tell if there exists a symlink that directly references a dir. (Same for indirect references.)

The best you could do is check every single file on the entire file system, but even that monumental effort wouldn't be perfect. For example, it won't find symlinks on devices that aren't currently mounted, it won't find foreign symlinks to shared portions of the file system, etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...