AIFile bug fixes.
Compare with errno instead of rc. Make sure errno is preserved.
This commit is contained in:
@@ -61,8 +61,8 @@ AIFile::~AIFile()
|
||||
//static
|
||||
void AIFile::mkdir(std::string const& dirname, int perms)
|
||||
{
|
||||
int rc = LLFile::mkdir(dirname, perms);
|
||||
if (rc < 0 && rc != EEXIST)
|
||||
int rc = LLFile::mkdir_nowarn(dirname, perms);
|
||||
if (rc < 0 && errno != EEXIST)
|
||||
{
|
||||
THROW_ERROR("AIFile_mkdir_Failed_to_create_DIRNAME", AIArgs("[DIRNAME]", dirname));
|
||||
}
|
||||
@@ -71,8 +71,8 @@ void AIFile::mkdir(std::string const& dirname, int perms)
|
||||
//static
|
||||
void AIFile::rmdir(std::string const& dirname)
|
||||
{
|
||||
int rc = LLFile::rmdir(dirname);
|
||||
if (rc < 0 && rc != ENOENT)
|
||||
int rc = LLFile::rmdir_nowarn(dirname);
|
||||
if (rc < 0 && errno != ENOENT)
|
||||
{
|
||||
THROW_ERROR("AIFile_rmdir_Failed_to_remove_DIRNAME", AIArgs("[DIRNAME]", dirname));
|
||||
}
|
||||
@@ -101,7 +101,8 @@ void AIFile::close(LLFILE* file)
|
||||
//static
|
||||
void AIFile::remove(std::string const& filename)
|
||||
{
|
||||
if (LLFile::remove(filename) < 0)
|
||||
int rc = LLFile::remove_nowarn(filename);
|
||||
if (rc < 0 && errno != ENOENT)
|
||||
{
|
||||
THROW_ERROR("AIFile_remove_Failed_to_remove_FILENAME", AIArgs("[FILENAME]", filename));
|
||||
}
|
||||
@@ -110,7 +111,7 @@ void AIFile::remove(std::string const& filename)
|
||||
//static
|
||||
void AIFile::rename(std::string const& filename, std::string const& newname)
|
||||
{
|
||||
if (LLFile::rename(filename, newname) < 0)
|
||||
if (LLFile::rename_nowarn(filename, newname) < 0)
|
||||
{
|
||||
THROW_ERROR("AIFile_rename_Failed_to_rename_FILE_to_NEWFILE", AIArgs("[FILE]", filename)("[NEWFILE]", newname));
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ int warnif(const std::string& desc, const std::string& filename, int rc, int acc
|
||||
}
|
||||
|
||||
// static
|
||||
int LLFile::mkdir(const std::string& dirname, int perms)
|
||||
int LLFile::mkdir_nowarn(const std::string& dirname, int perms)
|
||||
{
|
||||
#if LL_WINDOWS
|
||||
// permissions are ignored on Windows
|
||||
@@ -184,13 +184,19 @@ int LLFile::mkdir(const std::string& dirname, int perms)
|
||||
#else
|
||||
int rc = ::mkdir(dirname.c_str(), (mode_t)perms);
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
int LLFile::mkdir(const std::string& dirname, int perms)
|
||||
{
|
||||
int rc = LLFile::mkdir_nowarn(dirname, perms);
|
||||
// We often use mkdir() to ensure the existence of a directory that might
|
||||
// already exist. Don't spam the log if it does.
|
||||
return warnif("mkdir", dirname, rc, EEXIST);
|
||||
}
|
||||
|
||||
// static
|
||||
int LLFile::rmdir(const std::string& dirname)
|
||||
int LLFile::rmdir_nowarn(const std::string& dirname)
|
||||
{
|
||||
#if LL_WINDOWS
|
||||
// permissions are ignored on Windows
|
||||
@@ -200,6 +206,12 @@ int LLFile::rmdir(const std::string& dirname)
|
||||
#else
|
||||
int rc = ::rmdir(dirname.c_str());
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
int LLFile::rmdir(const std::string& dirname)
|
||||
{
|
||||
int rc = LLFile::rmdir_nowarn(dirname);
|
||||
return warnif("rmdir", dirname, rc);
|
||||
}
|
||||
|
||||
@@ -241,8 +253,7 @@ int LLFile::close(LLFILE * file)
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
|
||||
int LLFile::remove(const std::string& filename)
|
||||
int LLFile::remove_nowarn(const std::string& filename)
|
||||
{
|
||||
#if LL_WINDOWS
|
||||
std::string utf8filename = filename;
|
||||
@@ -251,10 +262,16 @@ int LLFile::remove(const std::string& filename)
|
||||
#else
|
||||
int rc = ::remove(filename.c_str());
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
int LLFile::remove(const std::string& filename)
|
||||
{
|
||||
int rc = LLFile::remove_nowarn(filename);
|
||||
return warnif("remove", filename, rc);
|
||||
}
|
||||
|
||||
int LLFile::rename(const std::string& filename, const std::string& newname)
|
||||
int LLFile::rename_nowarn(const std::string& filename, const std::string& newname)
|
||||
{
|
||||
#if LL_WINDOWS
|
||||
std::string utf8filename = filename;
|
||||
@@ -265,6 +282,12 @@ int LLFile::rename(const std::string& filename, const std::string& newname)
|
||||
#else
|
||||
int rc = ::rename(filename.c_str(),newname.c_str());
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
int LLFile::rename(const std::string& filename, const std::string& newname)
|
||||
{
|
||||
int rc = LLFile::rename_nowarn(filename, newname);
|
||||
return warnif(STRINGIZE("rename to '" << newname << "' from"), filename, rc);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,12 @@ public:
|
||||
|
||||
static int close(LLFILE * file);
|
||||
|
||||
// Singu extension: the same as below, but doesn't print a warning as to leave errno alone.
|
||||
static int mkdir_nowarn(const std::string& filename, int perms);
|
||||
static int rmdir_nowarn(const std::string& filename);
|
||||
static int remove_nowarn(const std::string& filename);
|
||||
static int rename_nowarn(const std::string& filename, const std::string& newname);
|
||||
|
||||
// perms is a permissions mask like 0777 or 0700. In most cases it will
|
||||
// be overridden by the user's umask. It is ignored on Windows.
|
||||
static int mkdir(const std::string& filename, int perms = 0700);
|
||||
|
||||
Reference in New Issue
Block a user