Bug 13426 - Loses track of data if file rename()d to same name
Summary: Loses track of data if file rename()d to same name
Status: RESOLVED FIXED
Alias: None
Product: Pseudo
Classification: Yocto Project Subprojects
Component: pseudo (show other bugs)
Version: master
Hardware: x86 Multiple
: Medium+ normal
Target Milestone: 3.2 M3
Assignee: Joe Slater
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2019-07-03 14:59 UTC by Ross Burton
Modified: 2020-08-28 09:39 UTC (History)
4 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments
Test case (465 bytes, text/plain)
2019-07-03 14:59 UTC, Ross Burton
no flags Details
testcase for rename() and renameat() (770 bytes, text/plain)
2020-08-26 12:01 UTC, Joe Slater
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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