1.1 --- a/fsaccess/op_copy_in.c Fri Jan 12 01:33:05 2024 +0100
1.2 +++ b/fsaccess/op_copy_in.c Fri Jan 12 01:33:31 2024 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Copy a file into a filesystem.
1.6 *
1.7 - * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2019, 2022, 2024 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -145,8 +145,15 @@
1.13
1.14 if (basename != NULL)
1.15 {
1.16 - sprintf(target_plus_basename, "%s/%s", target, basename);
1.17 - target_path = target_plus_basename;
1.18 + /* At the top level, omit the directory. */
1.19 +
1.20 + if (strlen(target))
1.21 + {
1.22 + sprintf(target_plus_basename, "%s/%s", target, basename);
1.23 + target_path = target_plus_basename;
1.24 + }
1.25 + else
1.26 + target_path = basename;
1.27 }
1.28 else
1.29 target_path = target;
1.30 @@ -205,7 +212,7 @@
1.31 /* Target filename details. */
1.32
1.33 char *target = argv[argc - 1];
1.34 - const char *basename;
1.35 + char *basename;
1.36 struct stat st;
1.37
1.38 /* Locate the target and test whether it is a file or a directory. */
1.39 @@ -219,6 +226,12 @@
1.40 /* Split the path, making target the parent directory. */
1.41
1.42 basename = path_split(target);
1.43 +
1.44 + /* Set the parent directory to the empty string if absent. */
1.45 +
1.46 + if (basename == target)
1.47 + target = basename + strlen(basename);
1.48 +
1.49 err = client_stat(target, &st);
1.50
1.51 if (err)