Re: FS Encoding error

2007-01-14 Thread Michael Gerz

Michael Gerz schrieb:

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?).


Georg, does it work on Linux?

Michael



Re: FS Encoding error

2007-01-14 Thread Enrico Forestieri
On Sat, Jan 13, 2007 at 07:25:51PM +0100, Michael Gerz wrote:

 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?).

I test your patch on cygwin and it works. I don't see any reason why
it should not work on linux. Only a suggestion: maybe you should rename
the bool variable successfulBackup as madeBackup or similar, as a backup
may not be attempted and the name could be misleading.

-- 
Enrico


Re: FS Encoding error

2007-01-14 Thread Michael Gerz

Enrico Forestieri schrieb:

On Sat, Jan 13, 2007 at 07:25:51PM +0100, Michael Gerz wrote:

  
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?).



I test your patch on cygwin and it works. I don't see any reason why
it should not work on linux. Only a suggestion: maybe you should rename
the bool variable successfulBackup as madeBackup or similar, as a backup
may not be attempted and the name could be misleading.
  


OK, I will rename the variable and commit.

Michael


Re: FS Encoding error

2007-01-14 Thread Georg Baum
Am Sonntag, 14. Januar 2007 10:52 schrieb Michael Gerz:

 Georg, does it work on Linux?

I can't see any reason why it should not. Just put it in, I'll test later.


Georg



Re: FS Encoding error

2007-01-14 Thread Michael Gerz

Michael Gerz schrieb:

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?).


Georg, does it work on Linux?

Michael



Re: FS Encoding error

2007-01-14 Thread Enrico Forestieri
On Sat, Jan 13, 2007 at 07:25:51PM +0100, Michael Gerz wrote:

> 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?).

I test your patch on cygwin and it works. I don't see any reason why
it should not work on linux. Only a suggestion: maybe you should rename
the bool variable successfulBackup as madeBackup or similar, as a backup
may not be attempted and the name could be misleading.

-- 
Enrico


Re: FS Encoding error

2007-01-14 Thread Michael Gerz

Enrico Forestieri schrieb:

On Sat, Jan 13, 2007 at 07:25:51PM +0100, Michael Gerz wrote:

  
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?).



I test your patch on cygwin and it works. I don't see any reason why
it should not work on linux. Only a suggestion: maybe you should rename
the bool variable successfulBackup as madeBackup or similar, as a backup
may not be attempted and the name could be misleading.
  


OK, I will rename the variable and commit.

Michael


Re: FS Encoding error

2007-01-14 Thread Georg Baum
Am Sonntag, 14. Januar 2007 10:52 schrieb Michael Gerz:

> Georg, does it work on Linux?

I can't see any reason why it should not. Just put it in, I'll test later.


Georg



Re: FS Encoding error

2007-01-13 Thread Georg Baum
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.


GeorgIndex: 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;


Re: FS Encoding error

2007-01-13 Thread Michael Gerz

Georg,

I am working on an alternative patch right now that fixes this and 
another bug (regarding backup failure).


Give me some time to polish it.

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


Re: FS Encoding error

2007-01-13 Thread Michael Gerz

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;
 }
 
 


Re: FS Encoding error

2007-01-13 Thread Georg Baum
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.


GeorgIndex: 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;


Re: FS Encoding error

2007-01-13 Thread Michael Gerz

Georg,

I am working on an alternative patch right now that fixes this and 
another bug (regarding backup failure).


Give me some time to polish it.

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


Re: FS Encoding error

2007-01-13 Thread Michael Gerz

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;
 }