Hi,
this patch fixes the encoding problem in the same way as Georg's patch.
However, I also fixed a potential problem that may occur if no backup
can be made successfully and I used proper variable names.
Folks, could someone please check this on Linux? A second Windows expert
would be fine, too (maybe someone who uses French accents in path names?).
Michael
Georg Baum schrieb:
Michael Gerz wrote:
Georg, Enrico,
something is wrong with the file encoding in Buffer::save(). If I save
changes to an (existing) file which is located in a path containing
German Umlauts (Windows), an exception is thrown. The exception message
isn't very useful. I says that the copy operation failed :-(
The value of pimpl_->filename.toFilesystemEncoding() is (console output):
C:/dokumente und einstellungen/me/eigene
dateien/foo/Veröffentlichungen/bar//foo.lyx
The value of s is:
C:/dokumente und einstellungen/me/eigene
dateien/foo/Veröffentlichungen/bar/foo.lyx~
Any idea? (I surprises me that I am the only one having this problem)
You seem to be the only one who uses non-ascii filenames with a non-utf8
filesystem. As you can see above the encoding of s is wrong, because s is
initialized with Buffer::fileName(). That gives a utf8-encoded string, but
we need one in the filesystem encoding.
The attached (untested) patch fixes that, if it works please put it in, I
don't have so much time currently.
Georg
Index: buffer.C
===================================================================
--- buffer.C (Revision 16664)
+++ buffer.C (Arbeitskopie)
@@ -713,41 +713,40 @@
// We don't need autosaves in the immediate future. (Asger)
resetAutosaveTimers();
+ string const encodedFilename = pimpl_->filename.toFilesystemEncoding();
+
+ FileName backupName;
+ bool successfulBackup = false;
+
// make a backup if the file already exists
- string s;
- if (lyxrc.make_backup &&
fs::exists(pimpl_->filename.toFilesystemEncoding())) {
- s = fileName() + '~';
+ if (lyxrc.make_backup && fs::exists(encodedFilename)) {
+ backupName = FileName(fileName() + '~');
if (!lyxrc.backupdir_path.empty())
- s = addName(lyxrc.backupdir_path,
- subst(os::internal_path(s),'/','!'));
+ backupName = FileName(addName(lyxrc.backupdir_path,
+
subst(os::internal_path(backupName.absFilename()), '/', '!')));
- // It might very well be that this variant is just
- // good enough. (Lgb)
- // But to use this we need fs::copy_file to actually do a copy,
- // even when the target file exists. (Lgb)
try {
- fs::copy_file(pimpl_->filename.toFilesystemEncoding(), s,
false);
- }
- catch (fs::filesystem_error const & fe) {
+ fs::copy_file(encodedFilename,
backupName.toFilesystemEncoding(), false);
+ successfulBackup = true;
+ } catch (fs::filesystem_error const & fe) {
Alert::error(_("Backup failure"),
- bformat(_("LyX was not able to make a
backup copy in %1$s.\n"
- "Please check if
the directory exists and is writeable."),
-
from_utf8(fs::path(s).branch_path().native_directory_string())));
- lyxerr[Debug::DEBUG] << "Fs error: "
- << fe.what() << endl;
+ bformat(_("Cannot create backup file
%1$s.\n"
+ "Please check whether the
directory exists and is writeable."),
+
from_utf8(backupName.absFilename())));
+ lyxerr[Debug::DEBUG] << "Fs error: " << fe.what() <<
endl;
}
}
if (writeFile(pimpl_->filename)) {
markClean();
removeAutosaveFile(fileName());
+ return true;
} else {
// Saving failed, so backup is not backup
- if (lyxrc.make_backup)
- rename(FileName(s), pimpl_->filename);
+ if (successfulBackup)
+ rename(backupName, pimpl_->filename);
return false;
}
- return true;
}