libutil/file-system: make AutoDelete not copyable and movable

Such a RAII structure should NEVER be copyable or movable, otherwise:

```
AutoDelete x;

x = AutoDelete(p, false);
```

will trigger the immediate deletion of `p`!

This fixes an annoying bug where the state record for cgroups was
deleted immediately as soon as it was created.

Change-Id: I2bfbc0815706700a0a75b79d1059cc552119b2c9
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
Raito Bezarius
2025-06-10 23:29:10 +02:00
parent 9f9fced2dd
commit 797c6d4cd4
2 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -330,7 +330,7 @@ void AutoDestroyCgroup::cleansePreviousInstancesAndRecordOurself(
}
writeFile(cgroupFile, std::get<std::filesystem::path>(cgroup_).string());
stateRecord = AutoDelete(cgroupFile, false);
stateRecord.reset(cgroupFile, false);
}
void AutoDestroyCgroup::adoptProcess(int pid)
+2
View File
@@ -273,6 +273,8 @@ class AutoDelete
bool del;
bool recursive;
public:
KJ_DISALLOW_COPY_AND_MOVE(AutoDelete);
AutoDelete();
AutoDelete(const Path & p, bool recursive = true);
~AutoDelete();