@@ -88,7 +88,7 @@ bool file_exists(const std::filesystem::path& path) {
8888 return std::filesystem::exists (path, ec);
8989}
9090
91- bool is_regular_file (const std::filesystem::path& path) {
91+ bool path_is_regular_file (const std::filesystem::path& path) {
9292 std::error_code ec;
9393 return std::filesystem::is_regular_file (path, ec);
9494}
@@ -311,7 +311,7 @@ std::optional<UpdateSource> find_update_source() {
311311 " /usr/local/share/openhd/update.zip" };
312312
313313 for (const auto & zip : zip_candidates) {
314- if (!is_regular_file (zip)) {
314+ if (!path_is_regular_file (zip)) {
315315 continue ;
316316 }
317317 if (is_recently_modified (zip, kStableSeconds )) {
@@ -510,6 +510,13 @@ bool install_deb_package(const std::filesystem::path& deb_path,
510510 return true ;
511511}
512512
513+ struct BinaryUpdate {
514+ std::filesystem::path source;
515+ std::filesystem::path target;
516+ };
517+
518+ bool apply_binary_update (const BinaryUpdate& update, std::ofstream& log);
519+
513520bool apply_deb_updates (const std::vector<std::filesystem::path>& debs,
514521 std::ofstream& log) {
515522 if (debs.empty ()) {
@@ -529,16 +536,16 @@ bool apply_deb_updates(const std::vector<std::filesystem::path>& debs,
529536 log_line (log, " dpkg-deb extract failed for " + deb.string ());
530537 return false ;
531538 }
532- const std::vector<BinaryUpdate> extracted = {
533- {temp_dir / " usr/local/bin/openhd" , " /usr/local/bin/openhd" },
534- {temp_dir / " usr/local/bin/QOpenHD" , " /usr/local/bin/QOpenHD" },
535- {temp_dir / " usr/local/bin/qopenhd" , " /usr/local/bin/QOpenHD" }};
536- for (const auto & item : extracted) {
537- if (is_regular_file (item.source )) {
538- if (!apply_binary_update (item, log)) {
539- return false ;
539+ const std::vector<BinaryUpdate> extracted = {
540+ {temp_dir / " usr/local/bin/openhd" , " /usr/local/bin/openhd" },
541+ {temp_dir / " usr/local/bin/QOpenHD" , " /usr/local/bin/QOpenHD" },
542+ {temp_dir / " usr/local/bin/qopenhd" , " /usr/local/bin/QOpenHD" }};
543+ for (const auto & item : extracted) {
544+ if (path_is_regular_file (item.source )) {
545+ if (!apply_binary_update (item, log)) {
546+ return false ;
547+ }
540548 }
541- }
542549 }
543550 std::error_code ec;
544551 std::filesystem::remove_all (temp_dir, ec);
@@ -561,11 +568,6 @@ bool apply_deb_updates(const std::vector<std::filesystem::path>& debs,
561568 return true ;
562569}
563570
564- struct BinaryUpdate {
565- std::filesystem::path source;
566- std::filesystem::path target;
567- };
568-
569571std::vector<BinaryUpdate> find_binary_updates (const std::filesystem::path& base) {
570572 std::vector<BinaryUpdate> updates;
571573 const std::filesystem::path bin_dir = base / " binaries" ;
@@ -577,19 +579,19 @@ std::vector<BinaryUpdate> find_binary_updates(const std::filesystem::path& base)
577579
578580 for (const auto & entry : candidates) {
579581 const auto source = bin_dir / entry.first ;
580- if (is_regular_file (source)) {
582+ if (path_is_regular_file (source)) {
581583 updates.push_back ({source, entry.second });
582584 }
583585 }
584586 return updates;
585587}
586588
587589bool apply_binary_update (const BinaryUpdate& update, std::ofstream& log) {
588- if (!is_regular_file (update.source )) {
590+ if (!path_is_regular_file (update.source )) {
589591 return true ;
590592 }
591593 std::error_code ec;
592- if (is_regular_file (update.target ) &&
594+ if (path_is_regular_file (update.target ) &&
593595 file_contents_equal (update.source , update.target )) {
594596 log_line (log, " Binary already matches: " + update.target .string ());
595597 return true ;
@@ -600,7 +602,7 @@ bool apply_binary_update(const BinaryUpdate& update, std::ofstream& log) {
600602 auto backup = update.target ;
601603 backup += " .bak" ;
602604
603- if (is_regular_file (update.target )) {
605+ if (path_is_regular_file (update.target )) {
604606 std::filesystem::copy_file (update.target , backup,
605607 std::filesystem::copy_options::overwrite_existing,
606608 ec);
@@ -611,11 +613,11 @@ bool apply_binary_update(const BinaryUpdate& update, std::ofstream& log) {
611613 ec);
612614 if (ec) {
613615 log_line (log, " Failed to copy " + update.source .string ());
614- if (is_regular_file (backup)) {
615- std::filesystem::copy_file (backup, update.target ,
616- std::filesystem::copy_options::overwrite_existing,
617- ec);
618- }
616+ if (path_is_regular_file (backup)) {
617+ std::filesystem::copy_file (backup, update.target ,
618+ std::filesystem::copy_options::overwrite_existing,
619+ ec);
620+ }
619621 return false ;
620622 }
621623 ::chmod (update.target.string().c_str(), 0755);
0 commit comments