mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-01-23 03:13:59 +08:00
Ensure dir
This commit is contained in:
parent
afe6f96611
commit
d024637e94
7
chsrc.c
7
chsrc.c
|
@ -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
22
chsrc.h
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user