Solved

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

Posted on 2007-04-02
3
367 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 100 total points
Comment Utility
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 84

Assisted Solution

by:ozo
ozo earned 100 total points
Comment Utility
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
Comment Utility
Thanks, both helpful
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
perl match and sort unique result 2 122
Perl Sort Question 4 117
Perl Awk Need Help 3 94
perl: Cleaning meta tags using RegEX 12 40
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now