From 320b76d95a488ce39a4d4b683a5424a2c57389bc Mon Sep 17 00:00:00 2001 From: Scott Wheeler Date: Tue, 13 Feb 2007 07:21:45 +0000 Subject: [PATCH] Rework the read-only check so that it gets along better with networked file systems. CCMAIL:apoikos@gmail.com git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@633092 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- taglib/toolkit/tfile.cpp | 11 +++++++++-- taglib/toolkit/tfile.h | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/taglib/toolkit/tfile.cpp b/taglib/toolkit/tfile.cpp index 7847a71f..ac4fd533 100644 --- a/taglib/toolkit/tfile.cpp +++ b/taglib/toolkit/tfile.cpp @@ -61,8 +61,15 @@ File::File(const char *file) { d = new FilePrivate(::strdup(file)); - d->readOnly = !isWritable(file); - d->file = fopen(file, d->readOnly ? "rb" : "rb+"); + // First try with read/write mode, if that fails, fall back to read only. + // We can't use ::access() since that works in odd ways on some file systems. + + d->file = fopen(file, "rb+"); + + if(d->file) + d->readOnly = false; + else + d->file = fopen(file,"rb"); if(!d->file) debug("Could not open file " + String(file)); diff --git a/taglib/toolkit/tfile.h b/taglib/toolkit/tfile.h index d736dcb9..02c87816 100644 --- a/taglib/toolkit/tfile.h +++ b/taglib/toolkit/tfile.h @@ -198,11 +198,15 @@ namespace TagLib { /*! * Returns true if \a file can be opened for reading. If the file does not * exist, this will return false. + * + * \deprecated */ static bool isReadable(const char *file); /*! * Returns true if \a file can be opened for writing. + * + * \deprecated */ static bool isWritable(const char *name);