From dadae20960b01a20f521b4d990cf8705971d0d76 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 23 Dec 2022 17:20:39 -0800 Subject: [PATCH] Remove unused implementations --- native/src/base/files.cpp | 45 +-------------------------------------- native/src/base/files.hpp | 12 ----------- 2 files changed, 1 insertion(+), 56 deletions(-) diff --git a/native/src/base/files.cpp b/native/src/base/files.cpp index f6a87cb1a..c3f901dc4 100644 --- a/native/src/base/files.cpp +++ b/native/src/base/files.cpp @@ -382,49 +382,6 @@ void parse_mnt(const char *file, const function &fn) { } } -void backup_folder(const char *dir, vector &files) { - char path[PATH_MAX]; - xrealpath(dir, path, sizeof(path)); - int len = strlen(path); - pre_order_walk(xopen(dir, O_RDONLY), [&](int dfd, dirent *entry) -> walk_result { - int fd = xopenat(dfd, entry->d_name, O_RDONLY); - if (fd < 0) - return SKIP; - run_finally f([&]{ close(fd); }); - if (fd_path(fd, byte_slice(path, sizeof(path))) < 0) - return SKIP; - raw_file file; - file.path = path + len + 1; - if (fgetattr(fd, &file.attr) < 0) - return SKIP; - if (entry->d_type == DT_REG) { - file.content = full_read(fd); - } else if (entry->d_type == DT_LNK) { - xreadlinkat(dfd, entry->d_name, path, sizeof(path)); - file.content = path; - } - files.emplace_back(std::move(file)); - return CONTINUE; - }); -} - -void restore_folder(const char *dir, vector &files) { - string base(dir); - // Pre-order means folders will always be first - for (raw_file &file : files) { - string path = base + "/" + file.path; - if (S_ISDIR(file.attr.st.st_mode)) { - mkdirs(path.data(), 0); - } else if (S_ISREG(file.attr.st.st_mode)) { - if (auto fp = xopen_file(path.data(), "we")) - fwrite(file.content.data(), 1, file.content.size(), fp.get()); - } else if (S_ISLNK(file.attr.st.st_mode)) { - symlink(file.content.data(), path.data()); - } - setattr(path.data(), &file.attr); - } -} - sDIR make_dir(DIR *dp) { return sDIR(dp, [](DIR *dp){ return dp ? closedir(dp) : 1; }); } @@ -491,10 +448,10 @@ mmap_data::mmap_data(const char *name, bool rw) { string find_apk_path(const char *pkg) { char buf[PATH_MAX]; + size_t len = strlen(pkg); pre_order_walk(xopen("/data/app", O_RDONLY), [&](int dfd, dirent *entry) -> walk_result { if (entry->d_type != DT_DIR) return SKIP; - size_t len = strlen(pkg); if (strncmp(entry->d_name, pkg, len) == 0 && entry->d_name[len] == '-') { fd_pathat(dfd, entry->d_name, buf, sizeof(buf)); return ABORT; diff --git a/native/src/base/files.hpp b/native/src/base/files.hpp index 08969d129..1a44100b9 100644 --- a/native/src/base/files.hpp +++ b/native/src/base/files.hpp @@ -39,16 +39,6 @@ protected: void swap(byte_data &o); }; -struct raw_file { - std::string path; - file_attr attr; - std::string content; - - raw_file() : attr{} {} - raw_file(const raw_file&) = delete; - raw_file(raw_file &&o) : path(std::move(o.path)), attr(o.attr), content(std::move(o.content)) {} -}; - struct mmap_data : public byte_data { mmap_data() = default; mmap_data(const mmap_data&) = delete; @@ -99,8 +89,6 @@ void parse_prop_file(const char *file, void frm_rf(int dirfd); void clone_dir(int src, int dest); void parse_mnt(const char *file, const std::function &fn); -void backup_folder(const char *dir, std::vector &files); -void restore_folder(const char *dir, std::vector &files); std::string find_apk_path(const char *pkg); using sFILE = std::unique_ptr;