PIVX Core  5.6.99
P2P Digital Currency
walletutil.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "wallet/walletutil.h"
6 #include "util/system.h"
7 
8 fs::path GetWalletDir()
9 {
10  fs::path path;
11 
12  if (gArgs.IsArgSet("-walletdir")) {
13  path = gArgs.GetArg("-walletdir", "");
14  if (!fs::is_directory(path)) {
15  // If the path specified doesn't exist, we return the deliberately
16  // invalid empty string.
17  path = "";
18  }
19  } else {
20  path = GetDataDir();
21  // If a wallets directory exists, use that, otherwise default to GetDataDir
22  if (fs::is_directory(path / "wallets")) {
23  path /= "wallets";
24  }
25  }
26 
27  return path;
28 }
29 
30 OperationResult VerifyWalletPath(const std::string& walletFile)
31 {
32  // Do some checking on wallet path. It should be either a:
33  //
34  // 1. Path where a directory can be created.
35  // 2. Path to an existing directory.
36  // 3. Path to a symlink to a directory.
37  // 4. For backwards compatibility, the name of a data file in -walletdir.
38  fs::path wallet_path = fs::absolute(walletFile, GetWalletDir());
39  fs::file_type path_type = fs::symlink_status(wallet_path).type();
40  if (!(path_type == fs::file_not_found || path_type == fs::directory_file ||
41  (path_type == fs::symlink_file && fs::is_directory(wallet_path)) ||
42  (path_type == fs::regular_file && fs::path(walletFile).filename() == walletFile))) {
43  return {false, (strprintf(
44  _("Invalid -wallet path '%s'. -wallet path should point to a directory where wallet.dat and "
45  "database/log.?????????? files can be stored, a location where such a directory could be created "
46  "or (for backwards compatibility) the name of an existing data file in -walletdir (%s)"),
47  walletFile, GetWalletDir()))};
48  }
49  return {true};
50 }
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:425
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:449
const fs::path & GetDataDir(bool fNetSpecific)
Definition: system.cpp:724
ArgsManager gArgs
Definition: system.cpp:89
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
Definition: system.h:65
#define strprintf
Definition: tinyformat.h:1056
fs::path GetWalletDir()
Get the path of the wallet directory.
Definition: walletutil.cpp:8
OperationResult VerifyWalletPath(const std::string &walletFile)
Verify the wallet db's path.
Definition: walletutil.cpp:30