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: src/buffer.C
===================================================================
--- src/buffer.C	(Revision 16667)
+++ src/buffer.C	(Arbeitskopie)
@@ -714,25 +714,25 @@ bool Buffer::save() const
 	resetAutosaveTimers();
 
 	// make a backup if the file already exists
-	string s;
-	if (lyxrc.make_backup && fs::exists(pimpl_->filename.toFilesystemEncoding())) {
-		s = fileName() + '~';
+	string const encoded_file = pimpl_->filename.toFilesystemEncoding();
+	FileName s;
+	if (lyxrc.make_backup && fs::exists(encoded_file)) {
 		if (!lyxrc.backupdir_path.empty())
-			s = addName(lyxrc.backupdir_path,
-				    subst(os::internal_path(s),'/','!'));
+			s = FileName(addName(lyxrc.backupdir_path,
+			                     subst(os::internal_path(pimpl_->filename.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);
+		    fs::copy_file(encoded_file, s.toFilesystemEncoding(), false);
 		}
 		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())));
+					  from_utf8(fs::path(s.absFilename()).branch_path().native_directory_string())));
 			lyxerr[Debug::DEBUG] << "Fs error: "
 					     << fe.what() << endl;
 		}
@@ -744,7 +744,7 @@ bool Buffer::save() const
 	} else {
 		// Saving failed, so backup is not backup
 		if (lyxrc.make_backup)
-			rename(FileName(s), pimpl_->filename);
+			rename(s, pimpl_->filename);
 		return false;
 	}
 	return true;

Reply via email to