mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-09 14:40:07 +00:00
Merge pull request #3322 from brauner/2020-03-24/fixes
utils: allow removal of immutable files
This commit is contained in:
commit
e4e80aa9e9
@ -19,6 +19,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
/* Needs to be after sys/mount.h header */
|
||||||
|
#include <linux/fs.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -129,12 +131,31 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
|
|||||||
if (_recursive_rmdir(pathname, pdev, exclude, level + 1, onedev) < 0)
|
if (_recursive_rmdir(pathname, pdev, exclude, level + 1, onedev) < 0)
|
||||||
failed = 1;
|
failed = 1;
|
||||||
} else {
|
} else {
|
||||||
if (unlink(pathname) < 0) {
|
ret = unlink(pathname);
|
||||||
|
if (ret < 0) {
|
||||||
|
__do_close int fd = -EBADF;
|
||||||
|
|
||||||
|
fd = open(pathname, O_RDONLY | O_CLOEXEC | O_NONBLOCK);
|
||||||
|
if (fd >= 0) {
|
||||||
|
/* The file might be marked immutable. */
|
||||||
|
int attr = 0;
|
||||||
|
ret = ioctl(fd, FS_IOC_GETFLAGS, &attr);
|
||||||
|
if (ret < 0)
|
||||||
|
SYSERROR("Failed to retrieve file flags");
|
||||||
|
attr &= ~FS_IMMUTABLE_FL;
|
||||||
|
ret = ioctl(fd, FS_IOC_SETFLAGS, &attr);
|
||||||
|
if (ret < 0)
|
||||||
|
SYSERROR("Failed to set file flags");
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = unlink(pathname);
|
||||||
|
if (ret < 0) {
|
||||||
SYSERROR("Failed to delete \"%s\"", pathname);
|
SYSERROR("Failed to delete \"%s\"", pathname);
|
||||||
failed = 1;
|
failed = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (rmdir(dirname) < 0 && !btrfs_try_remove_subvol(dirname) && !hadexclude) {
|
if (rmdir(dirname) < 0 && !btrfs_try_remove_subvol(dirname) && !hadexclude) {
|
||||||
SYSERROR("Failed to delete \"%s\"", dirname);
|
SYSERROR("Failed to delete \"%s\"", dirname);
|
||||||
|
Loading…
Reference in New Issue
Block a user