Skip to content

Check if MoveObject was called with the same src and dest location #612

Description

@carolynvs

CloudFilesProvider.MoveObject can end up deleting the object entirely if the source and destination location is the same. This doesn't happen with providers that support the move command, only with providers like Rackspace, where the SDK has to use a COPY + DELETE to accomplish a move.

using System.IO;
using System.Text;
using net.openstack.Core.Domain;
using net.openstack.Providers.Rackspace;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            const string region = "DFW";
            var user = new CloudIdentity
            {
                Username = "{username}",
                APIKey = "{apikey}"
            };

            var cloudFiles = new CloudFilesProvider(user);

            // Setup a test container and file
            cloudFiles.CreateContainer("test", region: region);
            var testObject = new MemoryStream(Encoding.UTF8.GetBytes("hello world"));
            cloudFiles.CreateObject("test", testObject, "helloworld.html", region: region);

            // Accidentally specify that the file should be moved to its current location
            cloudFiles.MoveObject("test", "helloworld.html", "test", "helloworld.html", region: region);

            /* This results in the file being copied "in-place" and then deleted. Fiddler output below:
            COPY /test/helloworld.html
            201 Created(text / html)

            HEAD /test/helloworld.html
            200 OK(text / html)

            DELETE /test/helloworld.html
            204 No Content (text / html)
            */
        }
    }
}

MoveObject should check if the source and destination are the same, and throw an argument exception to prevent accidentally deleting a file.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions