dropbox / dbxcli

A command line client for Dropbox built using the Go SDK
Other
1.04k stars 102 forks source link

Make cp command for a single source avoid preserving the original folder structure #172

Open lorisp1 opened 3 years ago

lorisp1 commented 3 years ago

Using cp command I noticed the following behaviour. Let's suppose I have File-A.txt within the following structure:

dbxcli.exe ls -l dbxcli/folderA/folder1
Revision              Size Last modified Path
5c5e6a3c10919314d4221 6 B  4 minutes ago /dbxcli/folderA/folder1/File-A.txt

while the following folder is empty:

dbxcli.exe ls -l dbxcli/folderB/folder1
Revision Size Last modified Path

Now I copy File-A.txt to dbxcli/folderB/folder1/File-A.txt:

dbxcli.exe cp dbxcli/folderA/folder1/File-A.txt dbxcli/folderB/folder1/File-A.txt

As a normal cp command, I'd expect to find the file in dbxcli/folderB/folder1/File-A.txt. Instead, File-A.txt is a folder that contains the whole original folder structure:

dbxcli.exe ls -l /dbxcli/folderB/folder1/File-A.txt/dbxcli/folderA/folder1
Revision              Size Last modified Path
5c5e6bd04b28f314d4221 6 B  1 minute ago  /dbxcli/folderB/folder1/File-A.txt/dbxcli/folderA/folder1/File-A.txt 

I can see the reason why it is important to preserve the original structure when you specify more than one source (i.e. avoiding name conflicts on the destination), but when there is a classic cp <from> <to> structure, I think it would be more useful to use the specified destination as the actual destination where the file/folder will be placed. Otherwise you would not be able to copy a single file from A to B.

The purpose of this merge request is changing cp command so that it preserves the original folder structure if and only if more than one source has been specified. Otherwise, it will work as a classic cp, having one source and one actual destination.

Starting from the same preconditions as the previous example, now cp would work as follows:

dbxcli.exe cp dbxcli/folderA/folder1/File-A.txt dbxcli/folderB/folder1/File-A.txt

dbxcli.exe ls -l /dbxcli/folderB/folder1 
Revision              Size Last modified  Path
5c611315ec247314d4221 6 B  25 seconds ago /dbxcli/folderB/folder1/File-A.txt
CLAassistant commented 2 years ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Loris Pozzobon seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.