LCOV - code coverage report
Current view: top level - src/wallet - walletutil.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 19 20 95.0 %
Date: 2025-02-23 09:33:43 Functions: 2 2 100.0 %

          Line data    Source code
       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        1482 : fs::path GetWalletDir()
       9             : {
      10        1482 :     fs::path path;
      11             : 
      12        1482 :     if (gArgs.IsArgSet("-walletdir")) {
      13          51 :         path = gArgs.GetArg("-walletdir", "");
      14          17 :         if (!fs::is_directory(path)) {
      15             :             // If the path specified doesn't exist, we return the deliberately
      16             :             // invalid empty string.
      17           0 :             path = "";
      18             :         }
      19             :     } else {
      20        1465 :         path = GetDataDir();
      21             :         // If a wallets directory exists, use that, otherwise default to GetDataDir
      22        4395 :         if (fs::is_directory(path / "wallets")) {
      23        1432 :             path /= "wallets";
      24             :         }
      25             :     }
      26             : 
      27        1482 :     return path;
      28             : }
      29             : 
      30         379 : 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        1139 :     fs::path wallet_path = fs::absolute(walletFile, GetWalletDir());
      39         379 :     fs::file_type path_type = fs::symlink_status(wallet_path).type();
      40         380 :     if (!(path_type == fs::file_not_found || path_type == fs::directory_file ||
      41           3 :           (path_type == fs::symlink_file && fs::is_directory(wallet_path)) ||
      42         387 :           (path_type == fs::regular_file && fs::path(walletFile).filename() == walletFile))) {
      43           2 :         return {false, (strprintf(
      44           2 :                 _("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           3 :                 walletFile, GetWalletDir()))};
      48             :     }
      49         379 :     return {true};
      50             : }

Generated by: LCOV version 1.14