zowe / zowe-cli

Zowe CLI
Eclipse Public License 2.0
116 stars 86 forks source link

zos-files delete uss fails wtih "The file could not be deleted" #313

Closed matthewpwilson closed 5 years ago

matthewpwilson commented 5 years ago
zowe files delete uss /u/user/foo.txt -f
Command Error:
z/OSMF REST API Error:
Rest API failure with HTTP(S) status 500
category: 8
rc:       -1
reason:   -1069678453
message:  remove() error
details: 
  - EDC5046I The file could not be deleted. (errno2=0xC012008B)

Error Details:
HTTP(S) error status "500" received.
Review request details (resource, base path, credentials, payload) and ensure correctness.

Host:      myhost.mycompany.com
Port:      32070
Base Path: 
Resource:  /zosmf/restfiles/fs/%2Fu%2Fuser%2Ffoo.txt
Request:   DELETE
Headers:   [{"X-CSRF-ZOSMF-HEADER":true}]
Payload:   undefined

It seems to be something to do with the URL encoding, if I make the same request to z/OSMF without the path encoded it works fine

ChrisBoehmCA commented 5 years ago

Maybe I made a mistake recommending that we encode all uss requests...but some things such as directories with spaces don't work without encoding. Maybe it's the extra slash at the beginning? If you do the request without the leading %2F e.g. /zosmf/restfiles/fs/u%2Fuser%2Ffoo.txt does it work? Maybe that's the bug @Alexandru-Dumitru any thoughts on this? Maybe we just need to not include the first character if it is a slash?

matthewpwilson commented 5 years ago

Yes, if I remove the leading %2F my REST request works, so this seems to be the culprit.

Alexandru-Dumitru commented 5 years ago

In Upload API we have this private function that is called on each path before building the z/OSMF REST call. This takes care of leading backslash. https://github.com/zowe/zowe-cli/blob/37e0fd7d63cc991e150b35a63da60163f199135a/packages/zosfiles/src/api/methods/upload/Upload.ts#L704

I think we should move it to ZosFilesUtils.ts and use it in the Delete API as well, so that this is taken care of automatically by the API, and the user can pass a full path as a command parameter.

Maybe even improve it? As I am thinking about it, it does trim just one backslash, but what if we have 2 or more? Is this something to take into consideration?

ChrisBoehmCA commented 5 years ago

Sounds good to me to move it into a shared Util location. I think it's good to take care of multiple leading slashes too

Alexandru-Dumitru commented 5 years ago

WIP at :https://github.com/Alexandru-Dumitru/zowe-cli/tree/fix_for_%23313