MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetWalletPath

Function GetWalletPath

src/wallet/wallet.cpp:2926–2963  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2924}
2925
2926util::Result<fs::path> GetWalletPath(const std::string& name)
2927{
2928 const fs::path name_path = fs::PathFromString(name);
2929
2930 // 'name' must be a normalized path, i.e. no . or .. except at the root
2931 if (name_path != name_path.lexically_normal()) {
2932 return util::Error{Untranslated("Wallet name given as a path must be normalized")};
2933 }
2934
2935 // 'name' cannot begin with ./ or ../
2936 if (!name_path.empty() && (*name_path.begin() == fs::PathFromString(".") || *name_path.begin() == fs::PathFromString(".."))) {
2937 return util::Error{Untranslated("Wallet name given as a relative path cannot begin with ./ or ../, for wallets not in the walletdir, please use an absolute path.")};
2938 }
2939
2940 // Disallow path at root
2941 if (name_path.has_root_path() && name_path.root_path() == name_path) {
2942 return util::Error{Untranslated("Wallet name cannot be the root path")};
2943 }
2944
2945 // Do some checking on wallet path. It should be either a:
2946 //
2947 // 1. Path where a directory can be created.
2948 // 2. Path to an existing directory.
2949 // 3. Path to a symlink to a directory.
2950 // 4. For backwards compatibility, the name of a data file in -walletdir.
2951 const fs::path wallet_path = fsbridge::AbsPathJoin(GetWalletDir(), name_path);
2952 fs::file_type path_type = fs::symlink_status(wallet_path).type();
2953 if (!(path_type == fs::file_type::not_found || path_type == fs::file_type::directory ||
2954 (path_type == fs::file_type::symlink && fs::is_directory(wallet_path)) ||
2955 (path_type == fs::file_type::regular && name_path.filename() == name_path))) {
2956 return util::Error{Untranslated(strprintf(
2957 "Invalid -wallet path '%s'. -wallet path should point to a directory where wallet.dat and "
2958 "database/log.?????????? files can be stored, a location where such a directory could be created, "
2959 "or (for backwards compatibility) the name of an existing data file in -walletdir (%s)",
2960 name, fs::quoted(fs::PathToString(GetWalletDir()))))};
2961 }
2962 return wallet_path;
2963}
2964
2965std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error_string)
2966{

Callers 3

ExecuteWalletToolFuncFunction · 0.85
MakeWalletDatabaseFunction · 0.85

Calls 9

PathFromStringFunction · 0.85
UntranslatedFunction · 0.85
AbsPathJoinFunction · 0.85
GetWalletDirFunction · 0.85
quotedFunction · 0.85
PathToStringFunction · 0.85
typeMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected