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.