From 1bc3b5ccef16024743d2255034485641e5dd9e3a Mon Sep 17 00:00:00 2001 From: YZBruh Date: Fri, 15 Aug 2025 11:52:03 +0300 Subject: [PATCH] pmt: CLeanup unnecessary function: real-link-path - real-link-path function is removed. - Added --real-link-path flag to real-path function for as real-link-path. --- USAGE.md | 20 ++++----- src/CMakeLists.txt | 1 - src/PartitionManager.cpp | 2 - src/functions/RealLinkPathFunction.cpp | 59 -------------------------- src/functions/RealPathFunction.cpp | 6 ++- src/functions/functions.hpp | 15 +------ 6 files changed, 14 insertions(+), 89 deletions(-) delete mode 100644 src/functions/RealLinkPathFunction.cpp diff --git a/USAGE.md b/USAGE.md index 5ff59e3..3b2d2ad 100644 --- a/USAGE.md +++ b/USAGE.md @@ -158,20 +158,16 @@ Show the **absolute block device path** for each partition. General syntax: pmt real-path partition(s) [OPTIONS] ``` +**Options:** +- `--real-link-path` → Tells real link path. + **Example usages:**\ -`pmt real-path boot` - Example output: `/dev/block/sda25` +`pmt real-path boot` - Example output: `/dev/block/sda25`\ +`pmt real-path boot --real-link-path` - Example output: `/dev/block/by-name/boot` --- -### 7. `real-linkpath` -Show the **symbolic link path** for each partition (e.g., `/dev/block/by-name/boot`). General syntax: -```bash -pmt real-link-path partition(s) [OPTIONS] -``` - ---- - -### 8. `type` +### 7. `type` Check magic numbers to determine file system or other types of partition(s) or image(s). General syntax: ```bash pmt type partition(s) [OPTIONS] @@ -188,7 +184,7 @@ pmt type partition(s) [OPTIONS] --- -### 9. `reboot` +### 8. `reboot` Reboot the device. Default reboot target is normal. If you are using it via ADB terminal, you **DO NOT** need root to use this feature. General syntax: ```bash pmt reboot [rebootTarget] [OPTIONS] @@ -201,7 +197,7 @@ pmt reboot [rebootTarget] [OPTIONS] --- -### 10. `memtest` +### 9. `memtest` Test your sequential (random tests is soon) read/write speed of your memory. ```bash pmt memtest [testPath] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1597b24..e747b0b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,7 +25,6 @@ set(PMT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/functions/MemoryTestFunction.cpp ${CMAKE_CURRENT_SOURCE_DIR}/functions/PartitionSizeFunction.cpp ${CMAKE_CURRENT_SOURCE_DIR}/functions/RealPathFunction.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/functions/RealLinkPathFunction.cpp ${CMAKE_CURRENT_SOURCE_DIR}/functions/RebootFunction.cpp ${CMAKE_CURRENT_SOURCE_DIR}/functions/TypeFunction.cpp ) diff --git a/src/PartitionManager.cpp b/src/PartitionManager.cpp index f3c0ccb..88cc2e8 100644 --- a/src/PartitionManager.cpp +++ b/src/PartitionManager.cpp @@ -96,8 +96,6 @@ int Main(int argc, char **argv) { AppMain); FuncManager.registerFunction(std::make_unique(), AppMain); FuncManager.registerFunction(std::make_unique(), AppMain); - FuncManager.registerFunction(std::make_unique(), - AppMain); FuncManager.registerFunction(std::make_unique(), AppMain); FuncManager.registerFunction(std::make_unique(), AppMain); FuncManager.registerFunction(std::make_unique(), diff --git a/src/functions/RealLinkPathFunction.cpp b/src/functions/RealLinkPathFunction.cpp deleted file mode 100644 index f6d4cb7..0000000 --- a/src/functions/RealLinkPathFunction.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright 2025 Yağız Zengin - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#include "functions.hpp" -#include - -#define RLPFUN "realPathFunction" - -namespace PartitionManager { -bool realLinkPathFunction::init(CLI::App &_app) { - LOGN(RLPFUN, INFO) << "Initializing variables of real link path function." - << std::endl; - cmd = _app.add_subcommand("real-linkpath", - "Tell real link paths of partition(s)"); - cmd->add_option("partition(s)", partitions, "Partition name(s)") - ->required() - ->delimiter(','); - return true; -} - -bool realLinkPathFunction::run() { - for (const auto &partition : partitions) { - if (!Variables->PartMap->hasPartition(partition)) - throw Error("Couldn't find partition: %s", partition.data()); - - if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) { - if (Variables->forceProcess) - LOGN(RLPFUN, WARNING) - << "Partition " << partition - << " is exists but not logical. Ignoring (from --force, -f)." - << std::endl; - else - throw Error("Used --logical (-l) flag but is not logical partition: %s", - partition.data()); - } - - println("%s", Variables->PartMap->getRealPathOf(partition).data()); - } - - return true; -} - -bool realLinkPathFunction::isUsed() const { return cmd->parsed(); } - -const char *realLinkPathFunction::name() const { return RLPFUN; } -} // namespace PartitionManager diff --git a/src/functions/RealPathFunction.cpp b/src/functions/RealPathFunction.cpp index b99d5eb..17044dc 100644 --- a/src/functions/RealPathFunction.cpp +++ b/src/functions/RealPathFunction.cpp @@ -27,6 +27,7 @@ bool realPathFunction::init(CLI::App &_app) { cmd->add_option("partition(s)", partitions, "Partition name(s)") ->required() ->delimiter(','); + cmd->add_flag("--real-link-path", realLinkPath, "Print real link path(s)")->default_val(false); return true; } @@ -46,7 +47,10 @@ bool realPathFunction::run() { partition.data()); } - println("%s", Variables->PartMap->getRealPathOf(partition).data()); + if (realLinkPath) + println("%s", Variables->PartMap->getRealLinkPathOf(partition).data()); + else + println("%s", Variables->PartMap->getRealPathOf(partition).data()); } return true; diff --git a/src/functions/functions.hpp b/src/functions/functions.hpp index f87e252..990be99 100644 --- a/src/functions/functions.hpp +++ b/src/functions/functions.hpp @@ -117,20 +117,7 @@ public: class realPathFunction final : public FunctionBase { private: std::vector partitions; - -public: - CLI::App *cmd = nullptr; - - bool init(CLI::App &_app) override; - bool run() override; - - [[nodiscard]] bool isUsed() const override; - [[nodiscard]] const char *name() const override; -}; - -class realLinkPathFunction final : public FunctionBase { -private: - std::vector partitions; + bool realLinkPath = false; public: CLI::App *cmd = nullptr;