filesystem_spec icon indicating copy to clipboard operation
filesystem_spec copied to clipboard

Expected behavior for "directory to new directory" depends on trailing slash

Open Github-dm-CDE opened this issue 1 year ago • 5 comments

In Copying files and directories, 1f case "directory to new directory", it is stated that the trailing slashes in both source and target are optional. However, if source/subdir and target/newdir/ are being used, the resulting target structure is the following:

📁 target
 └── 📁 newdir
     └── 📁 subdir
          ├── 📄 subfile1
          ├── 📄 subfile2
          └── 📁 nesteddir
              └── 📄 nestedfile

Basically the subdir folder itself is taken too, not only its content. This can be reproduced e.g. out of the box with LocalFileSystem() and the copy() method.

Is such output expected?

Github-dm-CDE avatar Jan 15 '24 15:01 Github-dm-CDE

Yes, this sounds exactly as designed, and what you would expect with a posix CLI. It also depends on whether the target directory already exists or not.

martindurant avatar Jan 15 '24 15:01 martindurant

Is then the behaviour specified in the documentation for single source to single target case 1f. Directory to new directoy incorrect @martindurant? Here the documentation specifies an expected output of:

cp("source/subdir/", "target/newdir/", recursive=True) (Whether with or without trailing slashes should result in the following structure)

📁 target
 └── 📁 newdir
     ├── 📄 subfile1
     └── 📄 subfile2
         └── 📁 nesteddir
             └── 📄 nestedfile

CM000n avatar Jan 16 '24 08:01 CM000n

"source/subdir/"

This path contains a terminal "/", so that is probably the difference. It would be best to make the cases with and without, versus expectations, test cases to be fixed. This is obviously not simple territory.

martindurant avatar Jan 16 '24 14:01 martindurant

The difference is definitely the trailing slash in the source path.

The thing is that the documentation explicitly states

Trailing slashes on both source and target are optional and do not affect the result.

So the first thing to clarify would be whether there is a problem in the documentation or in the implementation.

xebab avatar Jan 17 '24 08:01 xebab

I think that the documentation is correct, after all. There are test cases that are supposed to test that trailing slashes are optional.

Those tests were not executed, however. After enabling them they fail in accordance with the issue reported here.

xebab avatar Jan 18 '24 14:01 xebab