Commit df9a6a57 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis

file: Prompt user before deleting a non empty dir

Up until now, during object deletion, we could remove an object even
if other objects with its name as prefix existed (i.e. non empty
directory objects).

With this patch we add an extra warning and prompt the user
before the actual deletion takes place.
Signed-off-by: default avatarDimitris Aragiorgis <dimitris.aragiorgis@gmail.com>
parent fb8f0c17
......@@ -519,10 +519,31 @@ class file_delete(_PithosContainer):
self.client.get_object_info(self.path)
if self['yes'] or self.ask_user(
'Delete /%s/%s ?' % (self.container, self.path)):
self.client.del_object(
self.path,
until=self['until_date'],
delimiter='/' if self['recursive'] else self['delimiter'])
# See if any objects exist under prefix
# Add a trailing / to object's name
prefix = self.path.rstrip('/') + '/'
result = self.client.container_get(prefix=prefix)
if result.json:
count = len(result.json)
self.error(' * %d other object(s) with %s as prefix found' %
(count, prefix))
if self['recursive']:
msg = 'The above %d object(s) will be deleted, too' % \
count
else:
msg = 'The above %d object(s) will be preserved,' \
' but the directory structure' \
' will become inconsistent' % count
self.error(' * %s!' % msg)
if not result.json or self.ask_user("Continue?"):
self.client.del_object(
self.path,
until=self['until_date'],
delimiter='/' if self['recursive'] else self['delimiter'])
else:
self.error('Aborted')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment