From cbb309f5d4c09336bc9eeef772db784657e8815c Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Fri, 25 Mar 2005 09:11:08 +0000 Subject: [PATCH] Fix possible bug with adding a file 2 times to the drive_cache Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2151 --- src/dos/drive_local.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/dos/drive_local.cpp b/src/dos/drive_local.cpp index 4a8d6b43..70584476 100644 --- a/src/dos/drive_local.cpp +++ b/src/dos/drive_local.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: drive_local.cpp,v 1.55 2005-02-10 10:20:51 qbix79 Exp $ */ +/* $Id: drive_local.cpp,v 1.56 2005-03-25 09:11:08 qbix79 Exp $ */ #include #include @@ -53,13 +53,24 @@ bool localDrive::FileCreate(DOS_File * * file,char * name,Bit16u attributes) { strcpy(newname,basedir); strcat(newname,name); CROSS_FILENAME(newname); - FILE * hand=fopen(dirCache.GetExpandName(newname),"wb+"); + dirCache.ExpandName(newname); + /* Test if file exists (so we need to truncate it). don't add to dirCache then */ + bool existing_file=false; + + FILE * test=fopen(newname,"rb+"); + if(test) { + fclose(test); + existing_file=true; + + } + + FILE * hand=fopen(newname,"wb+"); if (!hand){ LOG_MSG("Warning: file creation failed: %s",newname); return false; } - dirCache.AddEntry(newname, true); + if(!existing_file) dirCache.AddEntry(newname, true); /* Make the 16 bit device information */ *file=new localFile(name,hand,0x202);