diff options
| author | Sebastian Valle <subv2112@gmail.com> | 2016-11-27 18:56:56 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-27 18:56:56 -0500 |
| commit | 4ba5acdaff19f5334b86e86c324763d4e9b969b0 (patch) | |
| tree | 408343a46858bcde292744d89fc6b3dadd9a54b0 /src/core/file_sys/path_parser.h | |
| parent | 77b7cec8afcaf9c267c8dbae49e123d980a32e73 (diff) | |
| parent | 282195b450721a5b8ad0cea8e66606b2661fe888 (diff) | |
Merge pull request #2132 from wwylele/fix-fs-err
Correct FS error codes & add path boundary checks
Diffstat (limited to 'src/core/file_sys/path_parser.h')
| -rw-r--r-- | src/core/file_sys/path_parser.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/core/file_sys/path_parser.h b/src/core/file_sys/path_parser.h new file mode 100644 index 000000000..990802579 --- /dev/null +++ b/src/core/file_sys/path_parser.h @@ -0,0 +1,61 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <string> +#include <vector> +#include "core/file_sys/archive_backend.h" + +namespace FileSys { + +/** + * A helper class parsing and verifying a string-type Path. + * Every archives with a sub file system should use this class to parse the path argument and check + * the status of the file / directory in question on the host file system. + */ +class PathParser { +public: + PathParser(const Path& path); + + /** + * Checks if the Path is valid. + * This function should be called once a PathParser is constructed. + * A Path is valid if: + * - it is a string path (with type LowPathType::Char or LowPathType::Wchar), + * - it starts with "/" (this seems a hard requirement in real 3DS), + * - it doesn't contain invalid characters, and + * - it doesn't go out of the root directory using "..". + */ + bool IsValid() const { + return is_valid; + } + + /// Checks if the Path represents the root directory. + bool IsRootDirectory() const { + return is_root; + } + + enum HostStatus { + InvalidMountPoint, + PathNotFound, // "/a/b/c" when "a" doesn't exist + FileInPath, // "/a/b/c" when "a" is a file + FileFound, // "/a/b/c" when "c" is a file + DirectoryFound, // "/a/b/c" when "c" is a directory + NotFound // "/a/b/c" when "a/b/" exists but "c" doesn't exist + }; + + /// Checks the status of the specified file / directory by the Path on the host file system. + HostStatus GetHostStatus(const std::string& mount_point) const; + + /// Builds a full path on the host file system. + std::string BuildHostPath(const std::string& mount_point) const; + +private: + std::vector<std::string> path_sequence; + bool is_valid{}; + bool is_root{}; +}; + +} // namespace FileSys |
