Ensure dir

This commit is contained in:
Aoran Zeng 2023-09-29 21:23:58 +08:00
parent afe6f96611
commit d024637e94
2 changed files with 25 additions and 4 deletions

View File

@ -1719,14 +1719,15 @@ wr_guix_setsrc (char* option)
}
void
wr_nix_check_cmd_()
wr_nix_check_cmd ()
{
char* check_cmd = xy_str_to_quietcmd("nix-channel --version");
bool exist = does_the_program_exist (check_cmd, "nix-channel");
if (!exist) {
xy_error ("chsrc: 未找到 nix-channel 命令,请检查是否存在");
chsrc_error ("未找到 nix-channel 命令,请检查是否存在");
exit(1);
}
}
@ -1739,7 +1740,7 @@ wr_nix_check_cmd_()
void
wr_nix_setsrc (char* option)
{
wr_nix_check_cmd_();
wr_nix_check_cmd ();
int index = use_specific_mirror_or_auto_select (option, wr_nix);

22
chsrc.h
View File

@ -3,7 +3,7 @@
* License : GPLv3
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-29>
* Last modified : <2023-09-27>
* Last modified : <2023-09-29>
*
* chsrc:
*
@ -291,10 +291,27 @@ chsrc_check_file (const char* path)
chsrc_run (cmd);
}
static void
chsrc_ensure_dir (const char* dir)
{
char* mkdir_cmd = NULL;
if (xy_on_windows) {
mkdir_cmd = "md ";
} else {
mkdir_cmd = "mkdir -p ";
}
char* cmd = xy_2strjoin (mkdir_cmd, dir);
cmd = xy_str_to_quietcmd (cmd);
chsrc_run (cmd);
}
static void
chsrc_append_to_file (const char* str, const char* file)
{
file = xy_uniform_path (file);
char* dir = xy_parent_dir (file);
chsrc_ensure_dir (dir);
char* cmd = NULL;
if (xy_on_windows) {
cmd = xy_strjoin (4, "echo ", str, " >> ", file);
@ -308,6 +325,9 @@ static void
chsrc_overwrite_file (const char* str, const char* file)
{
file = xy_uniform_path (file);
char* dir = xy_parent_dir (file);
chsrc_ensure_dir (dir);
char* cmd = NULL;
if (xy_on_windows) {
cmd = xy_strjoin (4, "echo ", str, " > ", file);