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

Commit 93fd29fc authored by Yumi Yukimura's avatar Yumi Yukimura
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 479211e8
Loading
Loading
Loading
Loading
+15 −11
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@
#include <unistd.h>
#include <unistd.h>


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


namespace fs = std::filesystem;

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


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


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


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


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

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


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