?
Solved

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

Posted on 2007-04-02
3
Medium Priority
?
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 84

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 …
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 …
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

800 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