From 485354928f044d4ecaf083c474bfad7f8a6d6764 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 21 Apr 2004 04:16:31 +0000 Subject: [PATCH] fix error reporting --- stepmania/src/RageFileDriver.h | 2 ++ stepmania/src/RageFileDriverZip.cpp | 2 +- stepmania/src/RageFileManager.cpp | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/stepmania/src/RageFileDriver.h b/stepmania/src/RageFileDriver.h index 899b419245..93e1481619 100644 --- a/stepmania/src/RageFileDriver.h +++ b/stepmania/src/RageFileDriver.h @@ -21,6 +21,8 @@ public: virtual void FlushDirCache( const CString &sPath ); virtual bool Remove( const CString &sPath ) { return false; } + /* Possible error returns from Open, in addition to standard errno.h values: */ + enum { ERROR_WRITING_NOT_SUPPORTED = -1 }; protected: FilenameDB *FDB; }; diff --git a/stepmania/src/RageFileDriverZip.cpp b/stepmania/src/RageFileDriverZip.cpp index 7c5f263a3d..5300b98bd3 100644 --- a/stepmania/src/RageFileDriverZip.cpp +++ b/stepmania/src/RageFileDriverZip.cpp @@ -452,7 +452,7 @@ RageFileObj *RageFileDriverZip::Open( const CString &path, int mode, RageFile &p { if( mode == RageFile::WRITE ) { - err = EINVAL; + err = ERROR_WRITING_NOT_SUPPORTED; return NULL; } diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index 3e5084f035..8fb7a7a06e 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -49,7 +49,7 @@ public: RageFileDriverMountpoints(): RageFileDriver( new FilenameDB ) { } RageFileObj *Open( const CString &path, int mode, RageFile &p, int &err ) { - err = (mode == RageFile::WRITE)? EINVAL:ENOENT; + err = (mode == RageFile::WRITE)? ERROR_WRITING_NOT_SUPPORTED:ENOENT; return NULL; } /* Never flush FDB, except in LoadFromDrivers. */ @@ -592,15 +592,9 @@ RageFileObj *RageFileManager::OpenForWriting( const CString &sPath, int mode, Ra Values.push_back( pair( i, value ) ); } - if( !Values.size() ) - { - err = EEXIST; - return NULL; - } - stable_sort( Values.begin(), Values.end(), SortBySecond ); - int error = 0; + err = 0; for( i = 0; i < Values.size(); ++i ) { const int driver = Values[i].first; @@ -608,14 +602,23 @@ RageFileObj *RageFileManager::OpenForWriting( const CString &sPath, int mode, Ra const CString path = ld.GetPath( sPath ); ASSERT( path.size() ); + int error; RageFileObj *ret = ld.driver->Open( path, mode, p, error ); if( ret ) { AddReference( ret, ld.driver ); return ret; } + + /* The drivers are in order of priority; if they all return error, return the + * first. Never return ERROR_WRITING_NOT_SUPPORTED. */ + if( !err && error != RageFileDriver::ERROR_WRITING_NOT_SUPPORTED ) + err = error; } - err = error; + + if( !err ) + err = EEXIST; /* no driver could write */ + return NULL; }