?
Solved

file system saftey: unlink vs rmtree vs system calls for directory removal

Posted on 2007-04-02
3
Medium Priority
?
426 Views
Last Modified: 2008-02-01
I keep hearing that I shouldn't use the unlink() command to remove directories because it could damage the file system and should use rmdir() instead.  

But rmdir only removes empty directories so a system call is sometimes easiest to remove directories with files still in them. (and I like to avoid system calls)

What I don't know is how safe is:
  use File::Path;
  rmtree(folder);

The use File::Path module seems to make use of both unlink and rmdir, but looks looks safe, but just want to ping you guys here first to see your experience .
0
Comment
Question by:Marketing_Insists
3 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 400 total points
ID: 18839519
the rmtree will use unlink for files and rmdir for directories.
If you specify the second parameter as 1 to rmtree, it will print how it is removing each file/dir (eg: whether it is using unlink or rmdir)
0
 
LVL 85

Assisted Solution

by:ozo
ozo earned 400 total points
ID: 18839523
unlink on a directory will fail unless the euid is the superuser, but it is the super user, and it doed not know what it is doing, it can damage the file system
File::Path::rmtree could have a problem if the direcrories are being altered while rmtree is running, or if rmtree is interupted while running
0
 

Author Comment

by:Marketing_Insists
ID: 18892620
Thanks, both helpful
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question