Hi I am sachin Puri I am new linux user. I have following observation in case of vim editor and have some question regarding it so whole scenario is like given below . What I have done and observe
Case 1 - I set all permissions (rwx) for owner on parent directory. (I am the owner.) $ ls -ld dir drwxrwxrwx 2 sachin sachin 4096 Mar 7 13:42 dir and has structhure like below /home/sachin/dir/text.text
In this case when editing the file "text.text", vim creates a temporary swap file in that directory. When the file is saved, the swap file is deleted and the inode number of "text.text" changes (it is different from the inode number of the original file and also the swap file).
Case 2 - Write permission is removed from parent directory $ ls -ld dir dr-xr-xr-x 2 sachin sachin 4096 Mar 7 13:42 dir
In this case when editing the file "text.text", vim creates a temporary swap file in /var/tmp. After saving the file, its inode does not change.
This means that in case 2, vim is updating the contents of the file in-place. I have found that OpenOffice.org also updates the contents in-place, irrespective of the parent directory permissions.
I wish to know why does vim create a new file in case 1. Wouldn't it be a costly operation, especially in case of large files? In short, which method is more efficient to implement for any file editor?
Please note that in all cases, all permissions are set on the file itself (i.e. text.text). I am just manipulating the permissions of the parent directory.
thanks in advance
On Mon, Mar 9, 2009 at 4:16 AM, sachin puri readsachin@gmail.com wrote:
Hi I am sachin Puri I am new linux user. I have following observation in case of vim editor and have some question regarding it so whole scenario is like given below . What I have done and observe
Case 1 - I set all permissions (rwx) for owner on parent directory. (I am the owner.) $ ls -ld dir drwxrwxrwx 2 sachin sachin 4096 Mar 7 13:42 dir and has structhure like below /home/sachin/dir/text.text
In this case when editing the file "text.text", vim creates a temporary swap file in that directory. When the file is saved, the swap file is deleted and the inode number of "text.text" changes (it is different from the inode number of the original file and also the swap file).
Case 2 - Write permission is removed from parent directory $ ls -ld dir dr-xr-xr-x 2 sachin sachin 4096 Mar 7 13:42 dir
In this case when editing the file "text.text", vim creates a temporary swap file in /var/tmp. After saving the file, its inode does not change.
This means that in case 2, vim is updating the contents of the file in-place. I have found that OpenOffice.org also updates the contents in-place, irrespective of the parent directory permissions.
I wish to know why does vim create a new file in case 1.
For recovery. If vim (or the network in case of remote files) crashes, the temp file can be useful. vim -r <file> to recover.
Wouldn't it be a costly operation, especially in case of large files? In short, which method is more efficient to implement for any file editor?
From your experiment it seems to be creating a temp file in both cases.
Please note that in all cases, all permissions are set on the file itself (i.e. text.text). I am just manipulating the permissions of the parent directory.
thanks in advance
On Mon, Mar 9, 2009 at 1:46 PM, sachin puri readsachin@gmail.com wrote:
I wish to know why does vim create a new file in case 1. Wouldn't it be a costly operation, especially in case of large files?
Not really if the swap file only records the changes / operations to the original in the swap. A la' journal if you will.
In short, which method is more efficient to implement for any file editor?
Depends on the files you are trying to edit.
However here's a strategy you can consider - 1. Start a journal for an edit session 2. Flush the journal every couple of seconds ( autosave ? )
Where this would fail is if the crash happens while flushing the journal. Then you would require a meta-journal .... :P
May the editor-makers on the list enlighten us on more strategies please !
regards, C
On Mon, Mar 9, 2009 at 8:28 AM, Chetan S cshring@gmail.com wrote:
On Mon, Mar 9, 2009 at 1:46 PM, sachin puri readsachin@gmail.com wrote:
I wish to know why does vim create a new file in case 1. Wouldn't it be a costly operation, especially in case of large files?
Not really if the swap file only records the changes / operations to the original in the swap. A la' journal if you will.
When (how often) does vim write out the swap file?
In short, which method is more efficient to implement for any file editor?
Depends on the files you are trying to edit.
However here's a strategy you can consider -
- Start a journal for an edit session
- Flush the journal every couple of seconds ( autosave ? )
Where this would fail is if the crash happens while flushing the journal. Then you would require a meta-journal .... :P
May the editor-makers on the list enlighten us on more strategies please !
regards, C -- http://mm.glug-bom.org/mailman/listinfo/linuxers
sachin puri wrote:
Case 2 - Write permission is removed from parent directory $ ls -ld dir dr-xr-xr-x 2 sachin sachin 4096 Mar 7 13:42 dir
In this case when editing the file "text.text", vim creates a temporary swap file in /var/tmp. After saving the file, its inode does not change.
This means that in case 2, vim is updating the contents of the file in-place. I have found that OpenOffice.org also updates the contents in-place, irrespective of the parent directory permissions.
I wish to know why does vim create a new file in case 1. Wouldn't it be a costly operation, especially in case of large files? In short, which method is more efficient to implement for any file editor?
Vim creates a swap file in all cases. Since you locked the dir with read only permissions, vim could not create/paste a swap file in dir. If you only change permissions in the parent directory (with no recursive option) you can edit existing files inside it but cannot add new ones or delete existing ones.