質問

I encountered an interesting behavior in Ubuntu bash, that I can't entirely understand. If I add extended file attribute to a file and then change it - attribute is dropped from file. Which from my point of view is ok.

user@user:~/tmp$ echo "aaa" > testattr
user@user:~/tmp$ setfattr --name "user.test" --value "Tested" testattr 
user@user:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
user@user:~/tmp$ vi testattr 
< change something in file and save it > 
user@user:~/tmp$ getfattr --name "user.test" testattr
testattr: user.test: No such attribute

But if I write something in file using bash - file attribute is left where it is. Can anybody explain such behavior?

user@user:~/tmp$ echo "aaa" > testattr
user@user:~/tmp$ setfattr --name "user.test" --value "Tested" testattr 
user@user:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
user@user:~/tmp$ echo "bbb" > testattr
user@user:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
役に立ちましたか?

解決

vi is deleting edited file and replacing it with new one. That's why attributes are not preserved.

This is log of operations on the file.

$ mkdir test
$ touch test/file
$ inotifywait -m -r test
Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
# vi is now running in another shell
test/ OPEN file
test/ CREATE .file.swp
test/ OPEN .file.swp
test/ CREATE .file.swpx
test/ OPEN .file.swpx
test/ CLOSE_WRITE,CLOSE .file.swpx
test/ DELETE .file.swpx
test/ CLOSE_WRITE,CLOSE .file.swp
test/ DELETE .file.swp
test/ CREATE .file.swp
test/ OPEN .file.swp
test/ MODIFY .file.swp
test/ ATTRIB .file.swp
test/ CLOSE_NOWRITE,CLOSE file
test/ OPEN file
test/ CLOSE_NOWRITE,CLOSE file
test/ MODIFY .file.swp
test/ CREATE 4913
test/ OPEN 4913
test/ ATTRIB 4913
test/ CLOSE_WRITE,CLOSE 4913
test/ DELETE 4913
test/ MOVED_FROM file     # old file moved
test/ MOVED_TO file~
test/ CREATE file         # new file created
test/ OPEN file
test/ MODIFY file
test/ CLOSE_WRITE,CLOSE file
test/ ATTRIB file
test/ ATTRIB file
test/ MODIFY .file.swp
test/ DELETE file~
test/ CLOSE_WRITE,CLOSE .file.swp
test/ DELETE .file.swp

See this answer to disable that behaviour.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top