Skip to content

Commit

Permalink
Rework the read-only check so that it gets along better with networke…
Browse files Browse the repository at this point in the history
…d file systems.

CCMAIL:apoikos@gmail.com


git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@633092 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
  • Loading branch information
scotchi committed Feb 13, 2007
1 parent 2e8c6ea commit 320b76d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions taglib/toolkit/tfile.cpp
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions taglib/toolkit/tfile.h
Expand Up @@ -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);

Expand Down

0 comments on commit 320b76d

Please sign in to comment.