File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1050,9 +1050,58 @@ namespace vix::commands::BuildCommand
10501050 return std::nullopt ;
10511051 }
10521052
1053+ static fs::path vix_home_dir ()
1054+ {
1055+ #ifdef _WIN32
1056+ const char *home = std::getenv (" USERPROFILE" );
1057+ #else
1058+ const char *home = std::getenv (" HOME" );
1059+ #endif
1060+
1061+ if (home && *home)
1062+ {
1063+ return fs::path (home) / " .vix" ;
1064+ }
1065+
1066+ return fs::current_path () / " .vix" ;
1067+ }
1068+
1069+ static std::string json_escape_string (const std::string &value)
1070+ {
1071+ std::string out;
1072+ out.reserve (value.size ());
1073+
1074+ for (char c : value)
1075+ {
1076+ switch (c)
1077+ {
1078+ case ' \\ ' :
1079+ out += " \\\\ " ;
1080+ break ;
1081+ case ' "' :
1082+ out += " \\\" " ;
1083+ break ;
1084+ case ' \n ' :
1085+ out += " \\ n" ;
1086+ break ;
1087+ case ' \r ' :
1088+ out += " \\ r" ;
1089+ break ;
1090+ case ' \t ' :
1091+ out += " \\ t" ;
1092+ break ;
1093+ default :
1094+ out += c;
1095+ break ;
1096+ }
1097+ }
1098+
1099+ return out;
1100+ }
1101+
10531102 static void write_last_binary (const fs::path &path)
10541103 {
1055- const fs::path metaDir = fs::current_path () / " .vix " ;
1104+ const fs::path metaDir = vix_home_dir () ;
10561105 const fs::path metaFile = metaDir / " meta.json" ;
10571106
10581107 std::error_code ec;
@@ -1066,7 +1115,9 @@ namespace vix::commands::BuildCommand
10661115 return ;
10671116
10681117 out << " {\n " ;
1069- out << " \" last_binary\" : \" " << path.string () << " \"\n " ;
1118+ out << " \" last_binary\" : \" "
1119+ << json_escape_string (fs::absolute (path).string ())
1120+ << " \"\n " ;
10701121 out << " }\n " ;
10711122 }
10721123
You can’t perform that action at this time.
0 commit comments