Azure / azure-storage-android

Microsoft Azure Storage Library for Android
Apache License 2.0
81 stars 48 forks source link

Deleting a directory is not working #55

Closed JulianClemot closed 7 years ago

JulianClemot commented 7 years ago

I'm trying to delete a previously created directory. I've made sure that it's empty and that it exists, but everytime I use the delete function, I'm rejected with a 404 and a Error Message = 'The specified resource does not exist.' which triggers a StorageException. It is weird in many ways because I can create directories, create files, even delete files but I can't delete directories.

I have a valid SasToken, with rcwdl privileges.

My connection string is as follows:

FileEndpoint=https://kasne.file.core.windows.net;SharedAccessSignature=sv=2015-12-11&sr=s&sig=xxx&st=2017-08-08T15%3A10%3A20Z&se=2017-08-09T15%3A25%3A20Z&sp=rcwdl and my shareName is also valid (1d707d905f6b4ccaa27bd665fd528f9c).

Here is the code I use:

CloudStorageAccount storageAccount = CloudStorageAccount.parse(getConnectionString());
// Create the file storage client.
CloudFileClient fileClient = storageAccount.createCloudFileClient();
CloudFileShare share = fileClient.getShareReference(getShareName());
CloudFileDirectory rootDirectory = share.getRootDirectoryReference();
CloudFileDirectory folderToDelete= rootDirectory.getDirectoryReference("folderToDelete");
//I broke down the deleteIfExists() function in two to make sure the folder exists
//as I'll have other things to do if the folder exists, but using directly deleteIfExists() give the same
//result as delete()
if(folderToDelete.exists()) { //returns true
    folderToDelete.delete(); //returns a storage exception
}

This is the response I get when executing the exists() function:

{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Starting operation.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Starting operation with location 'PRIMARY' per location mode 'PRIMARY_ONLY'.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Starting request to 'https://kasne.file.core.windows.net/1d707d905f6b4ccaa27bd665fd528f9c/folderToDelete?sr=s&st=2017-08-08T15%3A10%3A20Z&api-version=2017-04-17&sp=rcwdl&restype=directory&se=2017-08-09T15%3A25%3A20Z&sv=2015-12-11&sig=xxx' at 'null'.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Waiting for response.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Response received. Status code = '200', Request ID = '88b3f82f-001a-0049-3bf3-104952000000', Content-MD5 = 'null', ETag = '"0x8D4D8ACF2D46C17"', Date = 'Wed, 09 Aug 2017 09:39:31 GMT'.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {A network error occurred before the HTTP response status and headers were received.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Processing response headers.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Response headers were processed successfully.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Processing response body.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Response body was parsed successfully.}
{09eea61a-b69a-429b-a6a0-8b0ffff51bcd}: {Operation completed.}

And this is the response for my actual delete request:

{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Starting operation.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Starting operation with location 'PRIMARY' per location mode 'PRIMARY_ONLY'.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Starting request to 'https://kasne.file.core.windows.net/1d707d905f6b4ccaa27bd665fd528f9c/folderToDelete?restype=directory' at 'null'.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Waiting for response.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Response received. Status code = '404', Request ID = '88b3f830-001a-0049-3cf3-104952000000', Content-MD5 = 'null', ETag = 'null', Date = 'Wed, 09 Aug 2017 09:39:31 GMT'.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {A network error occurred before the HTTP response status and headers were received.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Processing response headers.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Response headers were processed successfully.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Operation did not return the expected result or returned an exception.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Checking if the operation should be retried. Retry count = '0', HTTP status code = '404', Error Message = 'The specified resource does not exist.'.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {The next location has been set to 'PRIMARY', per location mode 'PRIMARY_ONLY'.}
{4ec40b80-76b4-4fbe-8d33-5282b9e3e03c}: {Retry policy did not allow for a retry. Failing. Error Message = 'The specified resource does not exist.'.}

I noticed that my SasToken is attached as a query parameter when doing the exists() request and not when doing my delete(), is this normal ? I looked at the Rest api documentation and it seems that the delete call needs a authorization header and I don't know if it's present in the call from the library.

jofri-msft commented 7 years ago

Hi @JulianClemot , I'll double check the code but I see if(folderToDelete.exists()) { //returns true v3.delete(); //returns a storage exception }

Where is v3 coming from? Why aren't you using folderToDelete.delete()? Also please obfuscate the sig in your sas token 😎 in any future comments

JulianClemot commented 7 years ago

Oops sorry, I meant folderToDelete.delete() in the first place. Just a copy/paste mistake but I'll edit my first post.

asorrin-msft commented 7 years ago

The SAS token not being in the query param is definitely the cause here. This looks like a bug in the library when we're building the DELETE call for directories, we're not checking for a SAS token the way we do for the other calls. We'll get it fixed.

jofri-msft commented 7 years ago

Yes, we are planning on doing another release next week to support new server side APIs and will include this fix in that release.

JulianClemot commented 7 years ago

Great. I'll close the issue when the new release is done then. Thanks for the quick feedback.

rimjhimdoshi commented 5 years ago

I am also facing the same issue. Can you please suggest if it is fixed? If yes, in which version?