Introduce FileName::changePermission() and fix ConverterCache.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22123 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-12-13 10:38:31 +00:00
parent c87b197cd8
commit 4e364577e3
3 changed files with 23 additions and 18 deletions

View File

@ -249,21 +249,6 @@ void ConverterCache::init()
}
static bool changeMode(FileName const & fname, unsigned long int mode)
{
if (mode == (unsigned long int)-1)
return true;
ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
if (!ofs)
return false;
ofs.close();
if (!chmod(fname, mode))
return false;
return true;
}
void ConverterCache::add(FileName const & orig_from, string const & to_format,
FileName const & converted_file) const
{
@ -307,7 +292,7 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format,
onlyFilename(item->cache_name.absFilename()))) {
LYXERR(Debug::FILES, "Could not copy file " << orig_from << " to "
<< item->cache_name);
} else if (!changeMode(item->cache_name, 0600)) {
} else if (!item->cache_name.changeMode(0600)) {
LYXERR(Debug::FILES, "Could not change file mode"
<< item->cache_name);
}
@ -316,7 +301,7 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format,
orig_from.checksum());
if (mover.copy(converted_file, new_item.cache_name,
onlyFilename(new_item.cache_name.absFilename()))) {
if (!changeMode(new_item.cache_name, 0600)) {
if (!new_item.cache_name.changeMode(0600)) {
LYXERR(Debug::FILES, "Could not change file mode"
<< new_item.cache_name);
}

View File

@ -60,7 +60,9 @@ struct FileName::Private
Private() {}
Private(string const & abs_filename) : fi(toqstr(abs_filename))
{}
{
fi.setCaching(fi.exists() ? true : false);
}
///
QFileInfo fi;
};
@ -148,6 +150,21 @@ bool FileName::renameTo(FileName const & name) const
}
bool FileName::changePermission(unsigned long int mode) const
{
if (!fname.isWritable()) {
LYXERR0("File " << *this << " is not writable!");
return false;
}
if (!chmod(fname, mode)) {
LYXERR0("File " << *this << " cannot be changed to " << mode << " mode!");
return false;
}
return true;
}
string FileName::toFilesystemEncoding() const
{
QByteArray const encoded = QFile::encodeName(d->fi.absoluteFilePath());

View File

@ -102,6 +102,9 @@ public:
/// \retrun true on success.
bool renameTo(FileName const & target) const;
/// change mode of pointed file.
/// \retrun true on success.
bool changeMode(unsigned long int mode) const;
/// remove directory and all contents, returns true on success
bool destroyDirectory() const;