Creating a pseudo folder with the same name of one object at the same level would overwrite the object into a folder

Bug #1031150 reported by Ke Wu
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Object Storage (swift)
Invalid
Undecided
Unassigned

Bug Description

If you upload a file with same name as one subfolder, the file won't be uploaded. However if you create a new subfolder with the same name of one object, the object will be overwritten.

Say I have a container called test, the contents are:

pseudo-1/ (pseudo folder)
file-1 (actual file)

Now I try to upload a actual file to test with the file name "pseudo-1", the file won't be uploaded.

However, if I try to create a new pseudo folder named "file-1", the original actual file would be overwritten by the newly created pseudo folder.

Upload file code:
api = cloudfiles.get_connection(auth=auth)
container = api(request).get_container(container_name)
obj = container.create_object(object_name)
obj.send(object_file)

Create pseudo folder code:
container = api(request).get_container(container_name)
obj = container.create_object(folder_name)
obj.headers = {'content-type':'application/directory','content-length':0}
obj.send('')
obj.sync_metadata()

Revision history for this message
gholt (gholt) wrote :

You may have to describe this a bit better. Also, please note that there are no actual folders in Swift. There is the concept of pseudo folders, but that is based on the names of objects.

Swift has accounts at the topmost level, then containers within an account, then a flat list of objects within a container. Imagine this list of objects in a container:

one
one/a
one/a/1/i
two/b/2/ii

This is four objects in a flat list. Pseudo directories are understood as

one/
one/a/
one/a/1/
two/
two/b/
two/b/2/

But these aren't actual objects, they're just pseudo directories based on the names of objects that do exist.

Revision history for this message
Ke Wu (ke-wu) wrote :

I added some detail description

description: updated
description: updated
Revision history for this message
gholt (gholt) wrote :

Maybe it's a problem with the bindings? I tried what you described using curl and found no problems:

$ curl -XPUT http://127.0.0.1:8080/v1/AUTH_test/test -Hx-auth-token:AUTH_tkc747c5256d6a473fbf3d710ea5775e5d
201 Created

$ curl -XPUT http://127.0.0.1:8080/v1/AUTH_test/test/psuedo-1/ -Hcontent-type:application/directory -Hcontent-length:0 -Hx-auth-token:AUTH_tkc747c5256d6a473fbf3d710ea5775e5d
201 Created

$ curl -XPUT http://127.0.0.1:8080/v1/AUTH_test/test/file-1 -Hcontent-type:text/plain --data-binary '1234' -Hx-auth-token:AUTH_tkc747c5256d6a473fbf3d710ea5775e5d
201 Created

$ curl -XPUT http://127.0.0.1:8080/v1/AUTH_test/test/pseudo-1 -Hcontent-type:text/plain --data-binary 'abcd' -Hx-auth-token:AUTH_tkc747c5256d6a473fbf3d710ea5775e5d
201 Created

$ curl -XPUT http://127.0.0.1:8080/v1/AUTH_test/test/file-1/ -Hcontent-type:application/directory -Hcontent-length:0 -Hx-auth-token:AUTH_tkc747c5256d6a473fbf3d710ea5775e5d
201 Created

$ curl 'http://127.0.0.1:8080/v1/AUTH_test/test?format=json' -Hx-auth-token:AUTH_tkc747c5256d6a473fbf3d710ea5775e5d | python -mjson.tool
[
    {
        "bytes": 4,
        "content_type": "text/plain",
        "hash": "81dc9bdb52d04dc20036dbd8313ed055",
        "last_modified": "2012-07-31T01:51:20.844560",
        "name": "file-1"
    },
    {
        "bytes": 0,
        "content_type": "application/directory",
        "hash": "d41d8cd98f00b204e9800998ecf8427e",
        "last_modified": "2012-07-31T01:52:32.763770",
        "name": "file-1/"
    },
    {
        "bytes": 4,
        "content_type": "text/plain",
        "hash": "e2fc714c4727ee9395f324cd2e7f331f",
        "last_modified": "2012-07-31T01:51:53.382290",
        "name": "pseudo-1"
    },
    {
        "bytes": 0,
        "content_type": "application/directory",
        "hash": "d41d8cd98f00b204e9800998ecf8427e",
        "last_modified": "2012-07-31T01:50:02.712670",
        "name": "psuedo-1/"
    }
]

Revision history for this message
Ke Wu (ke-wu) wrote :

I noticed that when you create new pseudo folder, you have a "/" after the folder's name, I tried without the slash and got following result, as you can see without the slash the pseudo folder get overwritten. Does this mean the pseudo folder's name must be followed by a "/" ?

create a new container:

curl -XPUT http://10.211.55.102:8080/v1/AUTH_test/test -Hx-auth-token:d94abbc396094eeaa02da16cdbab5fbb

add new pseudo folder
curl -XPUT http://10.211.55.102:8080/v1/AUTH_test/test/psuedo-1 -Hcontent-type:application/directory -Hcontent-length:0 -Hx-auth-token:d94abbc396094eeaa02da16cdbab5fbb

list objects:
curl http://10.211.55.102:8080/v1/AUTH_test/test?format=json -Hx-auth-token:d94abbc396094eeaa02da16cdbab5fbb | python -mjson.tool

    {
        "bytes": 0,
        "content_type": "application/directory",
        "hash": "d41d8cd98f00b204e9800998ecf8427e",
        "last_modified": "2012-08-01T18:11:04.739910",
        "name": "psuedo-1"
    }

add a file with the same name as the pseudo folder:
curl -XPUT http://10.211.55.102:8080/v1/AUTH_test/test/psuedo-1 -Hcontent-type:text/plain --data-binary '1234' -Hx-auth-token:d94abbc396094eeaa02da16cdbab5fbb

list the objects:
curl http://10.211.55.102:8080/v1/AUTH_test/test?format=json -Hx-auth-token:d94abbc396094eeaa02da16cdbab5fbb | python -mjson.tool
    {
        "bytes": 4,
        "content_type": "text/plain",
        "hash": "81dc9bdb52d04dc20036dbd8313ed055",
        "last_modified": "2012-08-01T18:13:45.011280",
        "name": "psuedo-1"
    }

Revision history for this message
John Dickinson (notmyname) wrote :

This is not a bug and Swift is working as intended. For more information on pseudo-directories, look at http://docs.openstack.org/api/openstack-object-storage/1.0/content/pseudo-hierarchical-folders-directories.html

Changed in swift:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.