Compare commits

...

4 Commits

Author SHA1 Message Date
Yu Watanabe 669c7b687b
Merge 5e2d802c01 into b8cb1bc983 2024-11-06 15:13:44 +01:00
Yu Watanabe 5e2d802c01 bootctl: do not try to update the same file multiple times
Otherwise, copy_file_with_version_check() -> version_check() will fail
and warn about that the same version is already installed.

Fixes a regression caused by 929f41c652.
Fixes #33392.
2024-06-19 16:17:47 +09:00
Yu Watanabe f3159f9389 bootctl: check file type before update
This also adds missing assertions.

Follow-up for 929f41c652.
2024-06-19 16:17:47 +09:00
Yu Watanabe 8393fab8e0 bootctl: add missing error messages in version_check() 2024-06-19 16:17:47 +09:00
1 changed files with 15 additions and 4 deletions

View File

@ -194,14 +194,14 @@ static int version_check(int fd_from, const char *from, int fd_to, const char *t
if (r == -ESRCH)
return log_notice_errno(r, "Source file \"%s\" does not carry version information!", from);
if (r < 0)
return r;
return log_error_errno(r, "Failed to get version information of source file \"%s\": %m", from);
r = get_file_version(fd_to, &b);
if (r == -ESRCH)
return log_notice_errno(r, "Skipping \"%s\", it's owned by another boot loader (no version info found).",
to);
if (r < 0)
return r;
return log_error_errno(r, "Failed to get version information of \"%s\": %m", to);
if (compare_product(a, b) != 0)
return log_notice_errno(SYNTHETIC_ERRNO(ESRCH),
"Skipping \"%s\", it's owned by another boot loader.", to);
@ -324,11 +324,15 @@ static int create_subdirs(const char *root, const char * const *subdirs) {
return 0;
}
static int update_efi_boot_binaries(const char *esp_path, const char *source_path) {
static int update_efi_boot_binaries(const char *esp_path, const char *source_path, const char *exclude_path) {
_cleanup_closedir_ DIR *d = NULL;
_cleanup_free_ char *p = NULL;
int r, ret = 0;
assert(esp_path);
assert(source_path);
assert(exclude_path);
r = chase_and_opendir("/EFI/BOOT", esp_path, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, &p, &d);
if (r == -ENOENT)
return 0;
@ -339,9 +343,16 @@ static int update_efi_boot_binaries(const char *esp_path, const char *source_pat
_cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *v = NULL;
if (de->d_type != DT_REG)
continue;
if (!endswith_no_case(de->d_name, ".efi"))
continue;
/* Skip the file that is already updated. */
if (path_equal_filename(de->d_name, exclude_path))
continue;
fd = openat(dirfd(d), de->d_name, O_RDONLY|O_CLOEXEC);
if (fd < 0)
return log_error_errno(errno, "Failed to open \"%s/%s\" for reading: %m", p, de->d_name);
@ -422,7 +433,7 @@ static int copy_one_file(const char *esp_path, const char *name, bool force) {
/* If we were installed under any other name in /EFI/BOOT, make sure we update those binaries
* as well. */
if (!force)
RET_GATHER(ret, update_efi_boot_binaries(esp_path, source_path));
RET_GATHER(ret, update_efi_boot_binaries(esp_path, source_path, default_dest_path));
}
return ret;