473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File renaming

What would happen on Linux if:

$F=fopen("hello","wb");
lock $F
write to $F
rename "hello" as "mango"
close $F

Will mango contain upto date data ? Or will the rename cause it to
contain incomplete data ?

(I could have checked, but don't have Linux with me.)

Mike

Jul 17 '05 #1
4 1397
Why try to intentionally break things? Always close file handles before
moving files, just swap your last two lines of code around
"siliconmike" <si*********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
What would happen on Linux if:

$F=fopen("hello","wb");
lock $F
write to $F
rename "hello" as "mango"
close $F

Will mango contain upto date data ? Or will the rename cause it to
contain incomplete data ?

(I could have checked, but don't have Linux with me.)

Mike

Jul 17 '05 #2
Dave Turner <no****@nowhere.nohow> wrote:
Why try to intentionally break things? Always close file handles before
moving files, just swap your last two lines of code around


Why answer if you have (apprently) no idea how a unix filesystem works!
Will mango contain upto date data ? Or will the rename cause it to
contain incomplete data ?
I'm to lame to test but it should work.

A rename will only change the "name of the inode", since the inode is
already opened any (unflushed) buffers still point to the file formerly
known as hello.
(I could have checked, but don't have Linux with me.)


never leave home without a (eg knoppix) live CD :)

Jul 17 '05 #3
siliconmike wrote:
What would happen on Linux if:

$F=fopen("hello","wb");
lock $F
write to $F
rename "hello" as "mango"
close $F

Will mango contain upto date data ? Or will the rename cause it to
contain incomplete data ?

(I could have checked, but don't have Linux with me.)

Mike


A program in Linux uses the directory only to obtain the position of the
file on disk, that position is called an "inode".

So the file can be deleted or renamed even as it is being read/written. The
person doing the reading and writing is not affected by the fact that the
directory is entry is gone or renamed, they can continue to use the open
file handle.

However, once the last person with the file open closes it, then:

1) if it was deleted, nobody sees it anymore
2) if it was renamed, they have to use the new name
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #4
So, the sequence would work - I can conclude from Kenneth's advise. In
fact the reason I rename before closing the file is that I don't want
to unlock the file before renaming. This is to avoid certain race
conditions in my code.

Clarified
Thanks
Mike

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
4
by: b.milbrandt | last post by:
I am trying to convert a unix shell script to perl, and I have having a problem with the portion that copies files based on extension and renaming them in the process. I only trying to copy files...
7
by: Lalasa | last post by:
Hi, Can anybody tell me how many cpu cycles File.copy would take and how many cpu cycles File.Move would take? CFile::Rename in C++ takes just one cpu cycle. As there is no File.Rename in C#,...
1
by: MikeY | last post by:
Hopefully someone can help, I have a listview box where I display my desired files. I single click on the desired file to be renamed and I rename it with a new name. My problem arises when the...
6
by: Divya | last post by:
Hi, I have a web page which generates a CSV file based on some user input. When this file is downloaded by the user, the file is being automatically converted to .xls. Any idea how I can prevent...
1
by: Kyote | last post by:
I'm wanting to copy/move files from 1 directory to another in my program. I'm even doing a bit of renaming to help these specific files conform slightly to my preferred naming conventions to help...
5
by: bulldog8 | last post by:
I've read numerous posts and have tried multiple approaches that I found, but just cannot get a file renamed. I am using VB.Net 2002 ... Here is what I have tried: 1) Code common to all...
1
by: rn5a | last post by:
How do I find out whether a file is currently being used by some process or not (including the ASP.NET process)? A Web Form has a ListBox which lists all the directories & files existing in a...
1
by: arnuld | last post by:
I am trying to write a program that creates and renames log file on the system. I have created the initial design ( which of course is not compilable). Just asking whether this is the right way to...
36
by: Don | last post by:
I wrote an app that alerts a user who attempts to open a file that the file is currently in use. It works fine except when the file is opened by Notepad. If a text file is opened, most computers...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.