Accepting request 896791 from home:haasn:branches:Base:System
- add fallback for filesystems without renameat2 This change makes it succeed successfully on my system, which has a ZFS rootfs (so no renameat2). OBS-URL: https://build.opensuse.org/request/show/896791 OBS-URL: https://build.opensuse.org/package/show/Base:System/compat-usrmerge?expand=0&rev=11
This commit is contained in:
parent
f95836443b
commit
81fced0166
@ -1,3 +1,8 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Tue Jun 1 23:27:08 UTC 2021 - Niklas Haas <obs@haasn.xyz>
|
||||||
|
|
||||||
|
- add fallback for filesystems without renameat2
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Thu Mar 25 09:50:48 UTC 2021 - Ludwig Nussel <lnussel@suse.de>
|
Thu Mar 25 09:50:48 UTC 2021 - Ludwig Nussel <lnussel@suse.de>
|
||||||
|
|
||||||
|
30
xmv.c
30
xmv.c
@ -66,10 +66,34 @@ int main(int argc, char** argv)
|
|||||||
if (argc-optind < 2)
|
if (argc-optind < 2)
|
||||||
help(argv[0], 1);
|
help(argv[0], 1);
|
||||||
|
|
||||||
r = syscall (SYS_renameat2, AT_FDCWD, argv[optind], AT_FDCWD, argv[optind+1], RENAME_EXCHANGE);
|
const char *source = argv[optind], *target = argv[optind+1];
|
||||||
|
r = syscall (SYS_renameat2, AT_FDCWD, source, AT_FDCWD, target, RENAME_EXCHANGE);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
perror("renameat2");
|
if (errno != EINVAL) {
|
||||||
return 1;
|
perror("renameat2");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fallback for systems without renameat2 support */
|
||||||
|
char *tmp;
|
||||||
|
r = asprintf(&tmp, "%s.XXXXXX", target);
|
||||||
|
if (r < 0) {
|
||||||
|
perror("asprintf");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
mktemp(tmp);
|
||||||
|
|
||||||
|
r = renameat(AT_FDCWD, target, AT_FDCWD, tmp);
|
||||||
|
if (!r)
|
||||||
|
r = renameat(AT_FDCWD, source, AT_FDCWD, target);
|
||||||
|
if (!r)
|
||||||
|
r = renameat(AT_FDCWD, tmp, AT_FDCWD, source);
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
|
perror("renameat");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user