Merge pull request #27863 from DaanDeMeyer/copy-lock

Add helpers to lock a directory before copying into it
This commit is contained in:
Daan De Meyer
2023-06-20 15:22:24 +02:00
committed by GitHub
9 changed files with 123 additions and 54 deletions
+1 -1
View File
@@ -1177,7 +1177,7 @@ int xopenat_lock(
/* POSIX/UNPOSIX locks don't work on directories (errno is set to -EBADF so let's return early with
* the same error here). */
if (FLAGS_SET(open_flags, O_DIRECTORY) && locktype != LOCK_BSD)
if (FLAGS_SET(open_flags, O_DIRECTORY) && !IN_SET(locktype, LOCK_BSD, LOCK_NONE))
return -EBADF;
for (;;) {
+2
View File
@@ -174,6 +174,8 @@ int lock_generic(int fd, LockType type, int operation) {
assert(fd >= 0);
switch (type) {
case LOCK_NONE:
return 0;
case LOCK_BSD:
return RET_NERRNO(flock(fd, operation));
case LOCK_POSIX:
+1
View File
@@ -34,6 +34,7 @@ void unposix_unlockpp(int **fd);
_cleanup_(unposix_unlockpp) _unused_ int *CONCATENATE(_cleanup_unposix_unlock_, UNIQ) = &(fd)
typedef enum LockType {
LOCK_NONE, /* Don't lock the file descriptor. Useful if you need to conditionally lock a file. */
LOCK_BSD,
LOCK_POSIX,
LOCK_UNPOSIX,