Fix basename error with cp.com (#389)

This commit is contained in:
Gautham 2022-04-21 22:00:44 +05:30 committed by GitHub
parent 9d61e23c80
commit 01b25e267b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -73,14 +73,14 @@ void GetOpts(int argc, char *argv[]) {
int cp(const char *src, const char *dst) { int cp(const char *src, const char *dst) {
if (endswith(dst, "/") || isdirectory(dst)) { if (endswith(dst, "/") || isdirectory(dst)) {
dst = _gc(xasprintf("%s/%s", dst, basename)); dst = _gc(xasprintf("%s/%s", dst, basename(src)));
} }
if (!force && access(dst, W_OK) == -1 && errno != ENOENT) goto OnFail; if (!force && access(dst, W_OK) == -1 && errno != ENOENT) goto OnFail;
if (copyfile(src, dst, flags) == -1) goto OnFail; if (copyfile(src, dst, flags) == -1) goto OnFail;
return 0; return 0;
OnFail: OnFail:
fprintf(stderr, "%s %s %s: %s\n", "error: cp", src, dst, strerror(errno)); fprintf(stderr, "%s %s %s: %s\n", "error: cp", src, dst, strerror(errno));
return 1; return -1;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {