Skip to content

Commit 08a86e4

Browse files
committed
sparse_image_utils acquires flock on where real image is located at
1 parent 064238e commit 08a86e4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

base/cvd/cuttlefish/host/libs/image_aggregator/sparse_image.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ namespace {
3838

3939
constexpr std::string_view kAndroidSparseImageMagic = "\x3A\xFF\x26\xED";
4040

41-
Result<SharedFD> AcquireLock(const std::string& tmp_lock_image_path) {
41+
Result<SharedFD> AcquireLockForImage(const std::string& image_path) {
42+
std::string image_realpath;
43+
CF_EXPECT(android::base::Realpath(image_path, &image_realpath));
44+
std::string tmp_lock_image_path = image_realpath + ".lock";
4245
SharedFD fd =
4346
SharedFD::Open(tmp_lock_image_path.c_str(), O_RDWR | O_CREAT, 0666);
4447
CF_EXPECTF(fd->IsOpen(), "Failed to open '{}': '{}'", tmp_lock_image_path,
@@ -68,10 +71,10 @@ Result<bool> IsSparseImage(const std::string& image_path) {
6871
}
6972

7073
Result<void> ForceRawImage(const std::string& image_path) {
71-
std::string tmp_lock_image_path = image_path + ".lock";
72-
73-
SharedFD fd = CF_EXPECT(AcquireLock(tmp_lock_image_path));
74-
74+
if (!CF_EXPECT(IsSparseImage(image_path))) {
75+
return {};
76+
}
77+
SharedFD fd = CF_EXPECT(AcquireLockForImage(image_path));
7578
if (!CF_EXPECT(IsSparseImage(image_path))) {
7679
return {};
7780
}

0 commit comments

Comments
 (0)