{"action":"created","issue":{"url":"https://api.github.com/repos/minio/mc/issues/1122","labels_url":"https://api.github.com/repos/minio/mc/issues/1122/labels{/name}","comments_url":"https://api.github.com/repos/minio/mc/issues/1122/comments","events_url":"https://api.github.com/repos/minio/mc/issues/1122/events","html_url":"https://github.com/minio/mc/issues/1122","id":107854306,"number":1122,"title":"\"cp file dir\" not work","user":{"login":"akiradeveloper","id":785824,"avatar_url":"https://avatars.githubusercontent.com/u/785824?v=3","gravatar_id":"","url":"https://api.github.com/users/akiradeveloper","html_url":"https://github.com/akiradeveloper","followers_url":"https://api.github.com/users/akiradeveloper/followers","following_url":"https://api.github.com/users/akiradeveloper/following{/other_user}","gists_url":"https://api.github.com/users/akiradeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/akiradeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akiradeveloper/subscriptions","organizations_url":"https://api.github.com/users/akiradeveloper/orgs","repos_url":"https://api.github.com/users/akiradeveloper/repos","events_url":"https://api.github.com/users/akiradeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/akiradeveloper/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-23T05:51:03Z","updated_at":"2015-09-23T06:47:45Z","closed_at":null,"body":"I am writing tests for my s3 storage with mc. I have created a bucket named hoge and try to put a object named mytext.\r\n\r\nMy expectation is \"cp file dir\" is interpreted to \"cp file dir/file\" as in local filesystem because mc's goal is the transparent access to local and remote storages.\r\n\r\nIf I explicitly copy as \"cp mytext mys3/hoge/mytext\" copying succeeded.\r\n\r\nHere is the trace:\r\n\r\n```\r\nhayakawaakira-no-MacBook-Pro:~ akira$ mc --debug cp mytext mys3/hoge\r\nmc: <DEBUG> HEAD http://localhost:8080/hoge HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent:  Minio/2015-09-22T04:02:16.008862161Z (mc; darwin; amd64)\r\nAuthorization: AWS BCDEFGHIJKLMNOPQRSTA:6Esc4rOjEv/8qOfapzhGn923Msk=\r\nDate: Wed, 23 Sep 2015 05:38:38 GMT\r\n\r\nmc: <DEBUG> HTTP/1.1 404 Not Found\r\nConnection: close\r\nContent-Type: text/plain; charset=UTF-8\r\nDate: Wed, 23 Sep 2015 05:38:38 GMT\r\nServer: spray-can/1.3.3\r\n\r\nmc: <DEBUG> Response Time:  59.213951ms\r\n\r\nmc: <DEBUG> HEAD http://localhost:8080/hoge HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent:  Minio/2015-09-22T04:02:16.008862161Z (mc; darwin; amd64)\r\nAuthorization: AWS BCDEFGHIJKLMNOPQRSTA:6Esc4rOjEv/8qOfapzhGn923Msk=\r\nDate: Wed, 23 Sep 2015 05:38:38 GMT\r\n\r\nmc: <DEBUG> HTTP/1.1 404 Not Found\r\nConnection: close\r\nContent-Type: text/plain; charset=UTF-8\r\nDate: Wed, 23 Sep 2015 05:38:38 GMT\r\nServer: spray-can/1.3.3\r\n\r\nmc: <DEBUG> Response Time:  55.484399ms\r\n\r\nmc: <ERROR> Failed to copy ‘mytext’. Invalid Argument\r\n (3) .../src/github.com/minio/mc/cp-main.go:263 main.doCopyCmdSession.func1(..)\r\n (2) .../src/github.com/minio/mc/cp-main.go:133 main.doCopy(..)\r\n (1) .../src/github.com/minio/mc/common-methods.go:69 main.putTarget(..) Tags: [http://localhost:8080/hoge]\r\n (0) .../src/github.com/minio/mc/pkg/client/s3v2/s3.go:105 s3v2.(*s3Client).PutObject(..)\r\n Host:hayakawaakira-no-MacBook-Pro.local | OS:darwin | Arch:amd64 | Lang:go1.5.1 | Mem:1.2MB/5.8MB | Heap:1.2MB/2.6MB\r\n```"},"comment":{"url":"https://api.github.com/repos/minio/mc/issues/comments/142511308","html_url":"https://github.com/minio/mc/issues/1122#issuecomment-142511308","issue_url":"https://api.github.com/repos/minio/mc/issues/1122","id":142511308,"user":{"login":"harshavardhana","id":622699,"avatar_url":"https://avatars.githubusercontent.com/u/622699?v=3","gravatar_id":"","url":"https://api.github.com/users/harshavardhana","html_url":"https://github.com/harshavardhana","followers_url":"https://api.github.com/users/harshavardhana/followers","following_url":"https://api.github.com/users/harshavardhana/following{/other_user}","gists_url":"https://api.github.com/users/harshavardhana/gists{/gist_id}","starred_url":"https://api.github.com/users/harshavardhana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harshavardhana/subscriptions","organizations_url":"https://api.github.com/users/harshavardhana/orgs","repos_url":"https://api.github.com/users/harshavardhana/repos","events_url":"https://api.github.com/users/harshavardhana/events{/privacy}","received_events_url":"https://api.github.com/users/harshavardhana/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T06:47:45Z","updated_at":"2015-09-23T06:47:45Z","body":"> But this is bewildering because local filesystem cp a file in this way without the slash to claim it's a directory name.\r\n\r\n``mc cp`` will behave exactly the same as unix ``cp`` if the HEAD bucket succeeded,  a HEAD bucket is issued to know that if its a BUCKET so that we can construct the URL just like how unix ``cp`` does by knowing that the target is a directory -  for sending the PUT request. \r\n\r\nFor example on my local testing\r\n\r\n```\r\n$ mc cp api.go s3/ferenginar\r\napi.go:                       28.84 KB / 28.84 KB  ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓  100.00 % 90.07 KB/s 0\r\n\r\n```\r\n\r\nIn debug mode we can see, HEAD responds back properly for s3 and the copy succeeds. \r\n\r\n``` \r\nmc: <DEBUG> HEAD http://s3.amazonaws.com/ferenginar HTTP/1.1\r\nHost: s3.amazonaws.com\r\nUser-Agent:  Minio/2015-09-22T04:02:16.008862161Z (mc; darwin; amd64)\r\nAuthorization: AWS AKIAJVA5BMMU2RHO6IOQ:XcPvXZhHCxynmsgDD3U8YIwdbS4=\r\nDate: Wed, 23 Sep 2015 06:43:12 GMT\r\n\r\nmc: <DEBUG> HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nContent-Type: application/xml\r\nDate: Wed, 23 Sep 2015 06:43:14 GMT\r\nServer: AmazonS3\r\nX-Amz-Bucket-Region: us-east-1\r\nX-Amz-Id-2: DxArJLX7l6o9zyiiNtHmZxTMXmmp7groPr1DkPeg60SYuMUbOLkgdlahS0Faz4Mj\r\nX-Amz-Request-Id: 84AE4D83F8AD249E\r\n\r\n```\r\n\r\nNow the case when the full object path is specified, it still verifies by sending a HEAD that if the object exists. \r\n\r\n```\r\nmc: <DEBUG> HEAD http://s3.amazonaws.com/ferenginar/test.go HTTP/1.1\r\nHost: s3.amazonaws.com\r\nUser-Agent:  Minio/2015-09-22T04:02:16.008862161Z (mc; darwin; amd64)\r\nAuthorization: AWS AKIAJVA5BMMU2RHO6IOQ:2ZM/afLhV1HzAnPWvsoXyyEyGD0=\r\nDate: Wed, 23 Sep 2015 06:44:10 GMT\r\n\r\nmc: <DEBUG> HTTP/1.1 404 Not Found\r\nTransfer-Encoding: chunked\r\nContent-Type: application/xml\r\nDate: Wed, 23 Sep 2015 06:44:10 GMT\r\nServer: AmazonS3\r\nX-Amz-Id-2: IhDhP8bqxLqkbYO39cDdOO67AYzbwLkFbk+IoO0qvzdgt/RcXlg4BRmsgwSLSHLDzsu/icgLFtM=\r\nX-Amz-Request-Id: BFA1E4E33DEF3D91\r\n```\r\n\r\n```\r\nmc: <DEBUG> GET http://s3.amazonaws.com/ferenginar?max-keys=1000&prefix=test.go&delimiter=/ HTTP/1.1\r\nHost: s3.amazonaws.com\r\nUser-Agent:  Minio/2015-09-22T04:02:16.008862161Z (mc; darwin; amd64)\r\nAuthorization: AWS AKIAJVA5BMMU2RHO6IOQ:N338odV9k/+QAFc3XDZO0Zuj6+k=\r\nDate: Wed, 23 Sep 2015 06:44:11 GMT\r\nAccept-Encoding: gzip\r\n\r\nmc: <DEBUG> HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nContent-Type: application/xml\r\nDate: Wed, 23 Sep 2015 06:44:12 GMT\r\nServer: AmazonS3\r\nX-Amz-Bucket-Region: us-east-1\r\nX-Amz-Id-2: jkNwSXcPmx1Bx2fuDDeQTlMneUHKhdkbZBw3Pfstp5U4l0ymtaUvHSYT4L3Bwh2Gg7k0tPMCFJc=\r\nX-Amz-Request-Id: 7451EB13D65CC2DF\r\n\r\n``` \r\n\r\nI am assuming that you have implemented \"GET for buckets\" so it succeeded. "}}