path: root/gluster/swift/obj/
diff options
authorChetan Risbud <>2014-03-04 19:35:24 +0530
committerChetan Risbud <>2014-03-12 06:00:20 -0700
commit1a6b55714fddf7a1b526a31ee3f27589f01e98e5 (patch)
tree8d51f9dfa85e6eb17d1fa214949ed7de9daf8fda /gluster/swift/obj/
parent47cbf09a228040ea33918a472481f464ef9ad261 (diff)
PUT of a Directory failed
PUT of a directory fails with gluster-swift when there exists object of a same name. This is because the objects and directories are placed on the glusterfs. And hence the filesystem semantics are applicable there. Exceptions raised in such situation are needed to be handled and reported correctly back to proxy-server with HTTPConflict as a error code. Although swift still continues to choose 503 as the best respose in such cases. No tracebacks reported. Fix covers the case when there exists a directory and object of the same name is PUT. Code changes fixes both the failure cases mentioned in the bug. Examples of failing PUT requests: 1) curl -v -X PUT -d'asdasdsadA' -- obj2 was already an object. 2)curl -v -H 'Content-Length: 0' -H 'Content-Type: application/directory' -X PUT -- obj1 was already and object Bug: Change-Id: Id3042d920e3f99e740d4042ef5907ac8c59e04db Signed-off-by: Chetan Risbud <> Reviewed-on: Reviewed-by: Prashanth Pai <> Tested-by: Prashanth Pai <>
Diffstat (limited to 'gluster/swift/obj/')
1 files changed, 24 insertions, 10 deletions
diff --git a/gluster/swift/obj/ b/gluster/swift/obj/
index 3e4c5af..852f69f 100644
--- a/gluster/swift/obj/
+++ b/gluster/swift/obj/
@@ -29,6 +29,8 @@ from hashlib import md5
from eventlet import sleep
from greenlet import getcurrent
from contextlib import contextmanager
+from gluster.swift.common.exceptions import AlreadyExistsAsFile, \
+ AlreadyExistsAsDir
from swift.common.utils import TRUE_VALUES, ThreadPool, config_true_value
from swift.common.exceptions import DiskFileNotExist, DiskFileError, \
DiskFileNoSpace, DiskFileDeviceUnavailable, DiskFileNotOpen
@@ -166,17 +168,19 @@ def _make_directory_unlocked(full_path, uid, gid, metadata=None):
if not is_dir:
# FIXME: Ideally we'd want to return an appropriate error
# message and code in the PUT Object REST API response.
- raise DiskFileError("_make_directory_unlocked: os.mkdir"
- " failed on path %s because it already"
- " exists but not as a directory" % (
- full_path))
+ raise AlreadyExistsAsFile("_make_directory_unlocked:"
+ " os.mkdir failed on path %s"
+ " because it already exists"
+ " but not as a directory"
+ % (full_path))
return True, metadata
elif err.errno == errno.ENOTDIR:
# FIXME: Ideally we'd want to return an appropriate error
# message and code in the PUT Object REST API response.
- raise DiskFileError("_make_directory_unlocked: os.mkdir failed"
- " because some part of path %s is not in fact"
- " a directory" % (full_path))
+ raise AlreadyExistsAsFile("_make_directory_unlocked:"
+ " os.mkdir failed because some "
+ "part of path %s is not in fact"
+ " a directory" % (full_path))
elif err.errno == errno.EIO:
# Sometimes Fuse will return an EIO error when it does not know
# how to handle an unexpected, but transient situation. It is
@@ -482,6 +486,8 @@ class DiskFileWriter(object):
written to the temp file.
:param metadata: dictionary of metadata to be written
+ :raises AlreadyExistsAsDir : If there exists a directory of the same
+ name
assert self._tmppath is not None
metadata = _adjust_metadata(metadata)
@@ -497,9 +503,9 @@ class DiskFileWriter(object):
# system, perhaps gratuitously created when another
# object was created, or created externally to Swift
# REST API servicing (UFO use case).
- raise DiskFileError('DiskFile.put(): file creation failed since'
- ' the target, %s, already exists as a'
- ' directory' % df._data_file)
+ raise AlreadyExistsAsDir('DiskFile.put(): file creation failed'
+ ' since the target, %s, already exists'
+ ' as a directory' % df._data_file)
df._threadpool.force_run_in_thread(self._finalize_put, metadata)
@@ -897,6 +903,8 @@ class DiskFile(object):
:param size: optional initial size of file to explicitly allocate on
:raises DiskFileNoSpace: if a size is specified and allocation fails
+ :raises AlreadyExistsAsFile: if path or part of a path is not a \
+ directory
data_file = os.path.join(self._put_datadir, self._obj)
@@ -917,6 +925,12 @@ class DiskFile(object):
# Raise DiskFileNoSpace to be handled by upper layers when
# there is no space on disk OR when quota is exceeded
raise DiskFileNoSpace()
+ if gerr.errno == errno.ENOTDIR:
+ raise AlreadyExistsAsFile('do_open(): failed on %s,'
+ ' path or part of a'
+ ' path is not a directory'
+ % (tmppath))
if gerr.errno not in (errno.ENOENT, errno.EEXIST, errno.EIO):
# FIXME: Other cases we should handle?