473,320 Members | 1,982 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,320 software developers and data experts.

Files getting clobered

There was some disk space issues with my server. As a result any script
I had that opened a file for writing would clobber it i.e uncate it to
zero length . Since there was no space left on device, nothing would be
written to it.

Are there any workarounds to this? Does opening the r+ or w+ make a
difference instead of just w ?

May 18 '06 #1
2 1258
sq****@peoriadesignweb.com writes:
There was some disk space issues with my server. As a result any script
I had that opened a file for writing would clobber it i.e uncate it to
zero length . Since there was no space left on device, nothing would be
written to it.

Are there any workarounds to this? Does opening the r+ or w+ make a
difference instead of just w ?


w and w+ can be dangerous if you have disk space issues because they
truncate the file on open, without a check if you can write data to
the file again. So i suggest open with r+ and do a is_writable() (i
think it will return false if no disk space is avail) just before you
attempt to write, if it fails, close the file and no data is lost, if
it returns true you can ftruncate() the file to start from 0.
But there can still be issues, like if you dont have enough space to write
the entire content etc...

--
Henrik Hansen
May 18 '06 #2
>> There was some disk space issues with my server. As a result any script
I had that opened a file for writing would clobber it i.e uncate it to
zero length . Since there was no space left on device, nothing would be
written to it.

Are there any workarounds to this?
Buy a bigger disk?
Does opening the r+ or w+ make a
difference instead of just w ?
w and w+ can be dangerous if you have disk space issues because they
truncate the file on open, without a check if you can write data to
the file again.
If you're going to truncate the file, that's by itself dangerous
whether or not you can write data to the file.
So i suggest open with r+ and do a is_writable() (i
think it will return false if no disk space is avail) just before you
is_writable() should NOT return false if no disk space is available,
since you can still write to the existing portion of the file,
and just because there is disk space when you do is_writable() doesn't
mean there's disk space available when you write.
attempt to write, if it fails, close the file and no data is lost, if
it returns true you can ftruncate() the file to start from 0.
But there can still be issues, like if you dont have enough space to write
the entire content etc...


I recommend writing a new file (in the same directory as the old one),
and when you've finished it, rename it into place under its proper name.

Gordon L. Burditt
May 18 '06 #3

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

Similar topics

6
by: Robert Scheer | last post by:
Hi. I have two .js files that are used on several of my pages. I made some changes in one of the files. When I call the pages, the old functions are called because of the browser's cache. What...
9
by: John J. Hughes II | last post by:
Is it possible using Image or Bitmap to build and save an animated GIF file? I am not have a problem saving the GIF file just getting the frames added to it. I did find ImageAnimator but it only...
8
by: RML | last post by:
hey guys, i am looking at this piece of code that lists numbers of files in a directory. i want to convert it so it lists the files in th directory that end with .doc. i cant seem to get it to...
3
by: Jules | last post by:
i'm working with translators that just want to translate "web pages" and not deal with resource files. i'd like to have a file structure that looks sort of like this: / <- root directory where...
3
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On...
7
by: yoshitha | last post by:
Hi, In my application am using scrrun.dll to create files and folders and also to copy the files from one folder to another folder. Using my application i created 2 folders for eg folder1 and...
7
by: venkatbo | last post by:
Hi all, We've managed to cross-compile (from i686 targeting ppc) python (2.4.2) binaries and extension modules. However we cannot figure out how to cross-compile the .py (of distribution)...
7
by: Tyrone Showers | last post by:
I have a problem of getting the error "too many files open" and would like to trace my application. However, I have found nothing about how to display the current number of open files. Does...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: cxian | last post by:
Hi all, I am quite a beginner in PHP and happens that I have a problem with accessing remote files that gets me frustrated for two weeks now. This site I have running on PHP provide to download video...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.