Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Unlink command for opened files

Reply
Thread Tools

Unlink command for opened files

 
 
Prasanth
Guest
Posts: n/a
 
      04-16-2008
When a file is open does unlink automatically deletes the file or it
generates an error. Because I wrote a program to delete a file and
regenerate the file. if the file is not deleted the data simply gets
appended to the existing file. which results in wrong results
 
Reply With Quote
 
 
 
 
Joost Diepenmaat
Guest
Posts: n/a
 
      04-16-2008
Prasanth <> writes:

> When a file is open does unlink automatically deletes the file or it
> generates an error. Because I wrote a program to delete a file and
> regenerate the file. if the file is not deleted the data simply gets
> appended to the existing file. which results in wrong results


Unlink removes inodes, and it should succeed in that even if the file is
opened by any process. It does not empty files, if that's what you mean.


--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-16-2008
Prasanth <> wrote in
news:270a0c78-9d5e-4486-8b35-b429c4d61755
@u36g2000prf.googlegroups.co
m:

> When a file is open does unlink automatically deletes the file or
> it generates an error. Because I wrote a program to delete a file
> and regenerate the file. if the file is not deleted the data
> simply gets appended to the existing file. which results in wrong
> results


Hmmmm ... What is the question?

If you script opened the file, close it before calling unlink.

If the file is opened in exclusive mode by another process, I am not
sure deleting it is the correct action in the first place.

If you don't want your script to continue if unlink failed, you
should check the return value of unlink.

On the other hand, not that this will solve whatever problem you are
having, I would not have messed with unlink at all:

open my $out_h, '>', 'report.txt'
or die "Cannot open 'report.txt': $!";

That truncates the file if it can be opened and would die if it
cannot. Beats appending junk to a file.

There are just two many combinations of problems and solutions that
might apply to your post. Please elaborate after reading the posting
guidelines for this group and may be taking a look at the following
page:

http://blogs.msdn.com/oldnewthing/ar...5/8397753.aspx

Sinan

--
A. Sinan Unur <>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-16-2008
Joost Diepenmaat <> wrote in
news::

> Prasanth <> writes:
>
>> When a file is open does unlink automatically deletes the file or
>> it generates an error. Because I wrote a program to delete a file
>> and regenerate the file. if the file is not deleted the data
>> simply gets appended to the existing file. which results in wrong
>> results

>
> Unlink removes inodes, and it should succeed in that even if the
> file is opened by any process. It does not empty files, if that's
> what you mean.


I am guessing the OP is on Windows where

http://windowshelp.microsoft.com/Win...999831033.mspx

Sinan

--
A. Sinan Unur <>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      04-16-2008

Quoth Joost Diepenmaat <>:
> Prasanth <> writes:
>
> > When a file is open does unlink automatically deletes the file or it
> > generates an error. Because I wrote a program to delete a file and
> > regenerate the file. if the file is not deleted the data simply gets
> > appended to the existing file. which results in wrong results

>
> Unlink removes inodes, and it should succeed in that even if the file is
> opened by any process. It does not empty files, if that's what you mean.


Unlink removes *filenames*. Inodes are refcounted, and self-destruct
when there are no refs to them (including open file descriptors).

This only applies to Unixish filesystems, of course. Win32 won't let
you unlink an open file (under normal circumstances).

Ben

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      04-16-2008
Prasanth <> wrote:
>When a file is open does unlink automatically deletes the file or it
>generates an error.


That depends on the file system and/or operating system that you are
using.

jue
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-16-2008
Prasanth <> wrote:
> When a file is open does unlink automatically deletes the file or it
> generates an error. Because I wrote a program to delete a file and
> regenerate the file. if the file is not deleted the data simply gets
> appended to the existing file. which results in wrong results


This depends on your OS.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      04-16-2008
Chris Mattern <> wrote:
>On 2008-04-16, Prasanth <> wrote:
>> When a file is open does unlink automatically deletes the file or it
>> generates an error. Because I wrote a program to delete a file and
>> regenerate the file. if the file is not deleted the data simply gets
>> appended to the existing file. which results in wrong results

>
>This is not a Perl question, this is a question about the filesystem
>semantics for your particular operating system; the answer can differ
>from OS to OS. I'll talk about Unix/Linux, because that's the one I
>understand . In Unix/Linux, when you delete the file, you actually
>only delete the directory entry for the file.


This is getting somewhat off topic, but now you triggered my curiousity.
Does the behaviour really depend on the OS (as you seem to imply) or
does it depend on the file system? Or on both?
Example: FAT32 mounted on Linux. FAT32 does not have inodes or link
counts and I would guess that Linux would not allow deletion of a file
from a FAT32 partition as long as there is an open file descriptor
dangling. Is this true or does Linux simulate an inode and link count
structure on top of FAT?

jue

jue
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      04-16-2008

Quoth Jürgen Exner <>:
>
> This is getting somewhat off topic, but now you triggered my curiousity.
> Does the behaviour really depend on the OS (as you seem to imply) or
> does it depend on the file system? Or on both?
> Example: FAT32 mounted on Linux. FAT32 does not have inodes or link
> counts and I would guess that Linux would not allow deletion of a file
> from a FAT32 partition as long as there is an open file descriptor
> dangling. Is this true or does Linux simulate an inode and link count
> structure on top of FAT?


For both FAT and NFS (which doesn't support close-behind either) Linux
will fake the unlink by renaming the file to something 'unique', and
really deleting it after it's closed. Grep the kernel source for
'sillyrename'.

I don't know if all OSen provide (or attempt to provide) consistent
semantics across all filesystems they support.

Ben

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unlink command: <$files> argument fails dn.perl@gmail.com Perl Misc 3 10-31-2008 10:03 AM
perlcc error - 'Can't unlink error file...' Paul Urbanus Perl 0 04-07-2006 01:34 PM
os.unlink() AND win32api.DeleteFile() rbt Python 4 01-24-2006 01:17 PM
Accidentaly opened I-Bagle - and then opened virus vault ?? Morph Computer Information 2 02-01-2005 03:43 AM
unlink and big files Ruben van Engelenburg Perl Misc 1 11-09-2003 12:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57