renameat fails in apk-tools when upgrading a package where V1 has a directory and V2 has a file
We noticed the issue due to this bug: https://github.com/netdata/netdata/issues/5713
I can explain the use-case in detail if you’d like, but quite simply there’s an issue that we surfaced when upgrading packages.
Specifically at this line: https://git.alpinelinux.org/apk-tools/tree/src/database.c\#n2740 (and presumably at other places where renameat is called), when name is a directory, but tmpname is a file it fails with EISDIR.
I instrumented the line with this:
```
if (renameat(db->root_fd, tmpname,
db->root_fd, name) != 0) {
apk_error(PKG_VER_FMT“: failed to rename %s to %s (errno=%d,
strerror=%s EISDIR: %d).”,
PKG_VER_PRINTF(ipkg->pkg),
tmpname, name,
errno, strerror(errno), EISDIR);
ipkg->broken_files = 1;
}
```
And got this output:
```
ERROR: py2-psycopg2-2.7.5-r0: failed to rename
usr/lib/python2.7/site-packages/.apk.e6a4129270b3b99b221d1dbc3289eb2ec9dd67d2f0113746
to usr/lib/python2.7/site-packages/psycopg2-2.7.5-py2.7.egg-info
(errno=21, strerror=Is a directory EISDIR: 21).
```
A google search confirms this isn’t an isolated issue (https://www.google.com/search?source=hp&ei=tFOoXM-KFN6-0PEP9dKXgAY&q=alpine“failed+to+rename”&btnK=Google+Search&oq=alpine“failed+to+rename”&gs_l=psy-ab.3..33i22i29i30l10.852.2458..3285…0.0..0.83.614.11……0….1j2..gws-wiz…..0..0i131j0.DbDWol4S26w)
I’m a long-time Alpine user but new here, and I’ve read contributor guidelines. I’d be happy to submit patches and help in any way I can if you think this is a fix worth accepting.
I’d like to propose two changes. The first of which is to simply print `errno` and `strerror(errno)` as part of the error message - since the information is available at the failure site, it would really help everyone just see what the error was.
Secondly, I’d love guidance on what the expected semantics should be when V1 has a directory called Foo, but V2 makes it a file called Foo, and then I can submit patches to fix that.
Happy to hear thoughts, suggestions, comments.
(from redmine: issue id 10201, created on 2019-04-06)
- Uploads:
- 0001-Add-more-diagnostic-error-details-to-renameat-failur.patch The proposed patch for better debugging information