Merge pull request #29 from hiviah/fix_rmdir

Fix rmdir
This commit is contained in:
Michel Oosterhof
2015-08-20 22:24:07 +04:00

View File

@ -238,22 +238,27 @@ class command_rmdir(HoneyPotCommand):
def call(self): def call(self):
for f in self.args: for f in self.args:
path = self.fs.resolve_path(f, self.honeypot.cwd) path = self.fs.resolve_path(f, self.honeypot.cwd)
try:
if len(self.fs.get_path(path)): if len(self.fs.get_path(path)):
self.writeln( self.writeln(
'rmdir: failed to remove `%s\': Directory not empty' % f) 'rmdir: failed to remove `%s\': Directory not empty' % f)
continue continue
try:
dir = self.fs.get_path('/'.join(path.split('/')[:-1])) dir = self.fs.get_path('/'.join(path.split('/')[:-1]))
except IndexError: except (IndexError, FileNotFound):
dir = None dir = None
if not dir or f not in [x[A_NAME] for x in dir]: fname = os.path.basename(f)
if not dir or fname not in [x[A_NAME] for x in dir]:
self.writeln( self.writeln(
'rmdir: failed to remove `%s\': ' % f + \ 'rmdir: failed to remove `%s\': ' % f + \
'No such file or directory') 'No such file or directory')
continue continue
for i in dir[:]: for i in dir[:]:
if i[A_NAME] == f: if i[A_NAME] == fname:
if i[A_TYPE] != T_DIR:
self.writeln("rmdir: failed to remove '%s': Not a directory" % f)
return
dir.remove(i) dir.remove(i)
break
commands['/bin/rmdir'] = command_rmdir commands['/bin/rmdir'] = command_rmdir
class command_pwd(HoneyPotCommand): class command_pwd(HoneyPotCommand):