# HG changeset patch # User Paul Boddie # Date 1705019611 -3600 # Node ID 2a8305ea7970e00e61c245204c4debefedb121c5 # Parent b81f919d7e5f8eefc39457219f1e2400622ff89d Handle top-level directory copy operations. diff -r b81f919d7e5f -r 2a8305ea7970 fsaccess/op_copy_in.c --- a/fsaccess/op_copy_in.c Fri Jan 12 01:33:05 2024 +0100 +++ b/fsaccess/op_copy_in.c Fri Jan 12 01:33:31 2024 +0100 @@ -1,7 +1,7 @@ /* * Copy a file into a filesystem. * - * Copyright (C) 2019, 2022 Paul Boddie + * Copyright (C) 2019, 2022, 2024 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -145,8 +145,15 @@ if (basename != NULL) { - sprintf(target_plus_basename, "%s/%s", target, basename); - target_path = target_plus_basename; + /* At the top level, omit the directory. */ + + if (strlen(target)) + { + sprintf(target_plus_basename, "%s/%s", target, basename); + target_path = target_plus_basename; + } + else + target_path = basename; } else target_path = target; @@ -205,7 +212,7 @@ /* Target filename details. */ char *target = argv[argc - 1]; - const char *basename; + char *basename; struct stat st; /* Locate the target and test whether it is a file or a directory. */ @@ -219,6 +226,12 @@ /* Split the path, making target the parent directory. */ basename = path_split(target); + + /* Set the parent directory to the empty string if absent. */ + + if (basename == target) + target = basename + strlen(basename); + err = client_stat(target, &st); if (err)