Board index » delphi » Unwanted overwriting/deletion of files

Unwanted overwriting/deletion of files

Hi!

There is a huge problem that I have been trying to solve for many
months now and would be really happy if someone could help me:

Every now and then files are set to size zero or rewritten and filled
with some bytes of content.

This mostly happens to one particular file (BESTAND.DAT), which is
accessed very often, but also to some other files.

Most of the times the file had a size of 0 bytes after it happened.
But sometimes there was text in it which was actually written to the
LST file. LST is assigned to a temporary file to redirect the print
output.

We already have put a lot of check procedures into the sourcecode to
check if the LST file is assigned to the file BESTAND.DAT by checking
FileRec(lst).Name. This never was true, but anyway the problem
occured.

My guess is that the open file table in memory holds the name
BESTAND.DAT and an Assign fails and a following ReWrite uses a wrong
file name from the exisiting table. But can an Assign fail?

Do you have any idea how this can happen?

The problem occurs in Protected Mode and Windows programs compiled by
Borland Pascal 7.0. (real mode? I don't know) For the Windows version
I create a DLL file. The Windows DLL and the Protected Mode EXE-File
are about 3 MB big.

I would really appreciate hints or solutions to this really important
problem, which causes a lot of trouble to me.

Thanks a lot in advance!

Thomas Buehren
tho...@peperoni.de
(Could you please also answer to this address? Thanks!)

 

Re:Unwanted overwriting/deletion of files


Quote
Thomas Buehren <tho...@peperoni.de> wrote:

: There is a huge problem that I have been trying to solve for many
: months now and would be really happy if someone could help me:
:
: Every now and then files are set to size zero or rewritten and filled
: with some bytes of content.

        Is any equipment losing power or being turned off
while the program is running?
        Have you run a disk maintenance utility (CHKDSK
or SCANDISK for compatibles) to see if clusters of sectors
are being lost when this happens?
        Is there anyplace where the program can terminate
without a CLOSE FILE statement, like in a loop, if then,
or case statement?

: This mostly happens to one particular file (BESTAND.DAT), which is
: accessed very often, but also to some other files.

        Is there a place where ReWrite is used but
Append should be used.   Is the file closed properly
after modification?

: Most of the times the file had a size of 0 bytes after it happened.
: But sometimes there was text in it which was actually written to the
: LST file. LST is assigned to a temporary file to redirect the print
: output.

       That ought to be a clue to the problem.

: We already have put a lot of check procedures into the sourcecode to
: check if the LST file is assigned to the file BESTAND.DAT by checking
: FileRec(lst).Name. This never was true, but anyway the problem
: occured.
:
: My guess is that the open file table in memory holds the name
: BESTAND.DAT and an Assign fails and a following ReWrite uses a wrong
: file name from the exisiting table. But can an Assign fail?

       Rewrite sounds scary without the proper backup
code, especially if filenames are picked from a list
or table.
       As a tempory measure could the file be copied to
a backup file having a filename generated from the date
and time stamp?   That might save some important data
until the problem is resolved, and might provide a clue
to why the problem occurts.
       And, as a temporary measure, could the file be
renamed when it is supposed to be locked, or any method
to assure the lock is working?

: Do you have any idea how this can happen?

        No.  

Other Threads