ramccor / esmska

Automatically exported from code.google.com/p/esmska
0 stars 0 forks source link

unwanted change type of config file (link => regular file) #344

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. move some config file (e.g. ~/.config/esmska/settings.xml) to somewhere else.
2. create link (ln -s) to ~/.config/esmska/ directory)
3. run esmska and close it. While saving file during closing, it also changes 
type of file (it's not a link any more, but regular file).

What is the expected output? What do you see instead?
File should stay a link.

What version of Esmska are you using? On what operating system?
Tested on GNU/Linux, ext3 file system, esmska version 0.21.0

Please provide any additional information below.
Caused by using method moveFileSafely in class 
esmska.persistence.PersistenceManager. Why are you using method 
FileUtils.moveFile? I understand that backup config is needed, but why not just 
open backup file and write it's content to config file? It'd probably lead to 
more complicated code, but also preserve file type.

Original issue reported on code.google.com by petr.vo...@gmail.com on 15 Mar 2011 at 3:51

GoogleCodeExporter commented 9 years ago
It's pretty common for programs to write new configuration to temp file and 
then move the temp file over the original one. That prevents data corruption if 
system crashes in the middle of the process or until caches are flushed. 
Ideally you should have either original file or the new file, with no 
corruption (theory is one thing, reality another, but it at least increases 
chances substantially). Some fsync()-like calls are done after the renaming to 
ensure the process is complete.

My proposal is - use symlink for the whole config directory, not for a single 
config file. I.e.:
$ mv ~/.config/esmska /foo/bar
$ ln -s /foo/bar ~/.config/esmska
should work without problems. Does it solve your need?

Original comment by kamil.paral on 15 Mar 2011 at 6:31

GoogleCodeExporter commented 9 years ago
No, that's not, because I have simlinked just some files from /.config/esmska/. 
Well I understand that my problem pretty uncommon, so I'll either just simply 
live with it or write patch applied just by me.

Original comment by petr.vo...@gmail.com on 15 Mar 2011 at 8:58

GoogleCodeExporter commented 9 years ago
And what's the reason that you need to have just selected config files 
symlinked instead of the whole directory, if I may be so curious? Maybe there 
can another solution to your problem, if you explain the main purpose of your 
request.

Generally, I'm decided to stick to the principle of renaming files, because 
it's much safer for the users. And most of the users won't be able to recover 
their config files in the event of file inconsistency after system crash. But I 
am willing to do reasonable adjustments not breaking this principle, or provide 
an advice to solve your need in some other way.

Original comment by kamil.paral on 15 Mar 2011 at 9:46

GoogleCodeExporter commented 9 years ago
I perfectly understand the reason why you're renaming files. But the current 
implementation is:
1) copy old config file to backup
2) delete old config file // File backup = backupFile(destFile);
3) rename new config file to the old one

2) causes my problem :(. Best would be just to skip this and move new config 
file directly to the old one (after backup in 1) of course). Looking at Apache 
Commons sources tells me that it's not possible to move a file to an existing 
file (like mv in unixs does) - it would throw FileExistsException :(.
So I guess I just have to live with this feature :).

PS: I didn't symlinked whole directory, because I need to take some of the 
config files from different directories.

Original comment by petr.vo...@gmail.com on 15 Mar 2011 at 10:56

GoogleCodeExporter commented 9 years ago
You still didn't describe what you're trying to achieve. I guess you're trying 
to use several different esmska's profiles with shared contacts and other data. 
But that's just my guess.

To cut it short: I won't make any changes in saving the files. But you should 
be able to satisfy your use case e.g. by making a simple shell wrapper around 
esmska command, that will copy appropriate files into ~/.config/esmska before 
starting the program and copy them somewhere else after quitting the program. 
It depends on your needs.

I'm closing this ticket.

Original comment by kamil.paral on 16 Mar 2011 at 12:09