OSDN Git Service

[Refactor] fd_move() の引数をstring_view からpath に差し替えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Thu, 11 May 2023 11:42:54 +0000 (20:42 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 13 May 2023 12:56:33 +0000 (21:56 +0900)
src/save/save.cpp
src/util/angband-files.cpp
src/util/angband-files.h

index 974802b..91ee843 100644 (file)
@@ -320,9 +320,9 @@ bool save_player(PlayerType *player_ptr, SaveType type)
         auto savefile_old = ss_old.str();
         safe_setuid_grab(player_ptr);
         fd_kill(savefile_old);
-        const auto &filename = type == SaveType::DEBUG ? debug_savefile.string() : savefile.string();
-        fd_move(filename, savefile_old);
-        fd_move(savefile_new, filename);
+        const auto &path = type == SaveType::DEBUG ? debug_savefile : savefile;
+        fd_move(path, savefile_old);
+        fd_move(savefile_new, path);
         fd_kill(savefile_old);
         safe_setuid_drop();
         w_ptr->character_loaded = true;
index 6e14288..8c3352c 100644 (file)
@@ -359,23 +359,23 @@ void fd_kill(const std::filesystem::path &path)
 
 /*!
  * @brief OSごとの差異を吸収してファイルを移動する
- * @param from 移動元のファイルの相対パスまたは絶対パス
- * @param to 移動先のファイルの相対パスまたは絶対パス
+ * @param path_from 移動元のファイルの相対パスまたは絶対パス
+ * @param path_to 移動先のファイルの相対パスまたは絶対パス
  */
-void fd_move(std::string_view from, std::string_view to)
+void fd_move(const std::filesystem::path &path_from, const std::filesystem::path &path_to)
 {
-    const auto &path_from = path_parse(from);
-    if (!std::filesystem::exists(path_from)) {
+    const auto &abs_path_from = path_parse(path_from);
+    if (!std::filesystem::exists(abs_path_from)) {
         return;
     }
 
-    const auto &path_to = path_parse(to);
-    const auto directory = std::filesystem::path(path_to).remove_filename();
+    const auto &abs_path_to = path_parse(path_to);
+    const auto directory = std::filesystem::path(abs_path_to).remove_filename();
     if (!std::filesystem::exists(directory)) {
         std::filesystem::create_directory(directory);
     }
 
-    std::filesystem::rename(path_from, path_to);
+    std::filesystem::rename(abs_path_from, abs_path_to);
 }
 
 /*!
index fb00f3e..6cdbbea 100644 (file)
@@ -49,7 +49,7 @@ errr angband_fgets(FILE *fff, char *buf, ulong n);
 errr angband_fputs(FILE *fff, concptr buf, ulong n);
 errr angband_fclose(FILE *fff);
 void fd_kill(const std::filesystem::path &path);
-void fd_move(std::string_view from, std::string_view to);
+void fd_move(const std::filesystem::path &path_from, const std::filesystem::path &path_to);
 int fd_make(const std::filesystem::path &path, bool can_write_group = false);
 int fd_open(const std::filesystem::path &path, int mode);
 errr fd_lock(int fd, int what);