mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:34:59 +00:00
Utilities: Add -f option to ln
This commit is contained in:
parent
8bbf43318f
commit
eaeed259b0
1 changed files with 25 additions and 10 deletions
|
@ -16,11 +16,13 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool force = false;
|
||||
bool symbolic = false;
|
||||
const char* target = nullptr;
|
||||
const char* path = nullptr;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(force, "Force the creation", "force", 'f');
|
||||
args_parser.add_option(symbolic, "Create a symlink", "symbolic", 's');
|
||||
args_parser.add_positional_argument(target, "Link target", "target");
|
||||
args_parser.add_positional_argument(path, "Link path", "path", Core::ArgsParser::Required::No);
|
||||
|
@ -32,19 +34,32 @@ int main(int argc, char** argv)
|
|||
path = path_buffer.characters();
|
||||
}
|
||||
|
||||
if (symbolic) {
|
||||
int rc = symlink(target, path);
|
||||
do {
|
||||
if (symbolic) {
|
||||
int rc = symlink(target, path);
|
||||
if (rc < 0 && !force) {
|
||||
perror("symlink");
|
||||
return 1;
|
||||
} else if (rc == 0) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
int rc = link(target, path);
|
||||
if (rc < 0 && !force) {
|
||||
perror("link");
|
||||
return 1;
|
||||
} else if (rc == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int rc = unlink(path);
|
||||
if (rc < 0) {
|
||||
perror("symlink");
|
||||
perror("unlink");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
force = false;
|
||||
} while (true);
|
||||
|
||||
int rc = link(target, path);
|
||||
if (rc < 0) {
|
||||
perror("link");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue