Skip to content

Commit 6a00fe9

Browse files
committed
prefs: return success if nothing to delete
In the case that transaction submission is interrupted in between a delete an rename, upon next reboot, the prefs directory will not exist. Update_engine will attempt to swap prefs (e.g. rename prefs_tmp to prefs), but will fail here since prefs has already been deleted. We should return true if there is nothing to delete, and continue the rename Test: th Change-Id: I08725eb412f043187990c984caab049648c151ad
1 parent 0b735f6 commit 6a00fe9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

common/utils.cc

+12-7
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ bool SendFile(int out_fd, int in_fd, size_t count) {
412412
}
413413

414414
bool DeleteDirectory(const char* dirname) {
415+
if (!std::filesystem::exists(dirname)) {
416+
return true;
417+
}
415418
const std::string tmpdir = std::string(dirname) + "_deleted";
416419
std::filesystem::remove_all(tmpdir);
417420
if (rename(dirname, tmpdir.c_str()) != 0) {
@@ -620,28 +623,29 @@ bool SetBlockDeviceReadOnly(const string& device, bool read_only) {
620623
*/
621624
rc = ioctl(fd, BLKROGET, &read_only_flag);
622625
if (rc != 0) {
623-
PLOG(ERROR) << "Failed to read back block device read-only value:" << device;
626+
PLOG(ERROR) << "Failed to read back block device read-only value:"
627+
<< device;
624628
return false;
625629
}
626630
if (read_only_flag == expected_flag) {
627631
return true;
628632
}
629633

630634
std::array<char, PATH_MAX> device_name;
631-
char *pdevice = realpath(device.c_str(), device_name.data());
635+
char* pdevice = realpath(device.c_str(), device_name.data());
632636
TEST_AND_RETURN_FALSE_ERRNO(pdevice);
633637

634638
std::string real_path(pdevice);
635639
std::size_t offset = real_path.find_last_of('/');
636-
if (offset == std::string::npos){
640+
if (offset == std::string::npos) {
637641
LOG(ERROR) << "Could not find partition name from " << real_path;
638642
return false;
639643
}
640644
const std::string partition_name = real_path.substr(offset + 1);
641645

642646
std::string force_ro_file = "/sys/block/" + partition_name + "/force_ro";
643-
android::base::unique_fd fd_force_ro {
644-
HANDLE_EINTR(open(force_ro_file.c_str(), O_WRONLY | O_CLOEXEC))};
647+
android::base::unique_fd fd_force_ro{
648+
HANDLE_EINTR(open(force_ro_file.c_str(), O_WRONLY | O_CLOEXEC))};
645649
TEST_AND_RETURN_FALSE_ERRNO(fd_force_ro >= 0);
646650

647651
rc = write(fd_force_ro, expected_flag ? "1" : "0", 1);
@@ -650,12 +654,13 @@ bool SetBlockDeviceReadOnly(const string& device, bool read_only) {
650654
// Read back again
651655
rc = ioctl(fd, BLKROGET, &read_only_flag);
652656
if (rc != 0) {
653-
PLOG(ERROR) << "Failed to read back block device read-only value:" << device;
657+
PLOG(ERROR) << "Failed to read back block device read-only value:"
658+
<< device;
654659
return false;
655660
}
656661
if (read_only_flag != expected_flag) {
657662
LOG(ERROR) << "After modifying force_ro, marking block device " << device
658-
<< " as read_only=" << expected_flag;
663+
<< " as read_only=" << expected_flag;
659664
return false;
660665
}
661666
return true;

0 commit comments

Comments
 (0)