Solved

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

Posted on 2007-04-02
3
408 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 100 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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

728 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