Bug 13426

Summary: Loses track of data if file rename()d to same name
Product: [Yocto Project Subprojects] Pseudo Reporter: Ross Burton <ross.burton>
Component: pseudoAssignee: Joe Slater <joe.slater>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium+ CC: randy.macleod, seebs, yp.pseudo.watcher, yp.watcher
Version: master   
Target Milestone: 3.2 M3   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Attachments:
Description Flags
Test case
none
testcase for rename() and renameat() none

Description Ross Burton 2019-07-03 14:59:04 UTC
Created attachment 4535 [details]
Test case

Nothing stops rename() being told to rename foo to foo. For example this doesn't produe an error:

$ touch foo
$ python3 -c "import os; os.rename('foo', 'foo')"

However when run under pseudo the rename() wrappers throw away the information for the old name, losing ownership data etc.

Attached is a test case to demonstrate this.

A simple strcmp in the rename() wrapper is enough to fix this, although that's both horrible and doesn't fix renameat().
Comment 1 Randy MacLeod 2020-01-16 16:19:31 UTC
Seems mostly harmless but it might be causing some autobuilder failures or other problems.
Comment 2 Joe Slater 2020-08-21 13:07:39 UTC
Only just started looking, but it seems like if the target of a rename exists, info about it is deleted.  Then, the info for the renamed file is assigned to the rename target.  Of course, in this case, that info is gone.
Comment 3 Joe Slater 2020-08-25 15:56:26 UTC
In the appropriate "guts" files, move the check for old/new identity to before playing with the pseudo database.  Works for rename() and should work for renameat() and renameat2().
Comment 4 Joe Slater 2020-08-26 12:01:50 UTC
Created attachment 4716 [details]
testcase for rename() and renameat()
Comment 5 Randy MacLeod 2020-08-28 09:39:05 UTC
merged to master and seems to be passing tests so closing:
   https://git.openembedded.org/openembedded-core/commit/?id=6b3d109f42385ad1cf1f297a6c06ea7eb6509f26