Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 23c409da authored by Yumi Yukimura's avatar Yumi Yukimura Committed by Michael Bestas
Browse files

install: fuse_install: Browse directory using std::filesystem

* On ISO9660 FS, Everything has `de->d_type == DT_UNKNOWN`, which
  the previous logic don't handle

Change-Id: I038b71b7f603b2788cef4f17a42ab141d16def83
parent 39247483
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <unistd.h>

#include <algorithm>
#include <filesystem>
#include <functional>
#include <memory>
#include <string>
@@ -39,6 +40,8 @@
#include "install/install.h"
#include "recovery_utils/roots.h"

namespace fs = std::filesystem;

using android::volmgr::VolumeInfo;
using android::volmgr::VolumeManager;

@@ -58,8 +61,7 @@ static void SetSdcardUpdateBootloaderMessage() {

// Returns the selected filename, or an empty string.
std::string BrowseDirectory(const std::string& path, Device* device, RecoveryUI* ui) {
  std::unique_ptr<DIR, decltype(&closedir)> d(opendir(path.c_str()), closedir);
  if (!d) {
  if (access(path.c_str(), R_OK | X_OK)) {
    PLOG(ERROR) << "error opening " << path;
    return "";
  }
@@ -67,19 +69,21 @@ std::string BrowseDirectory(const std::string& path, Device* device, RecoveryUI*
  std::vector<std::string> dirs;
  std::vector<std::string> entries{ "../" };  // "../" is always the first entry.

  dirent* de;
  while ((de = readdir(d.get())) != nullptr) {
    std::string name(de->d_name);
  for (const auto& entry : fs::directory_iterator(path)) {
    std::string name = entry.path().filename().string();

    if (de->d_type == DT_DIR) {
    // Skip "." and ".." entries.
    if (name == "." || name == "..") continue;

    if (entry.is_directory()) {
      dirs.push_back(name + "/");
    } else if (de->d_type == DT_REG && (android::base::EndsWithIgnoreCase(name, ".zip") ||
                                        android::base::EndsWithIgnoreCase(name, ".map"))) {
    } else if (entry.is_regular_file()) {
      if (android::base::EndsWithIgnoreCase(name, ".zip") ||
          android::base::EndsWithIgnoreCase(name, ".map")) {
        entries.push_back(name);
      }
    }
  }

  std::sort(dirs.begin(), dirs.end());
  std::sort(entries.begin(), entries.end());