(self, force=False, recursive=False)
return True
Delete files or directories
Delete files or directories
Delete files or directories
def remove(self, force=False, recursive=False):
        """Delete files or directories"""
        if not os.path.lexists(self.filename):
            pass
        elif self.filename.count("/") < 2:
            Msg().err("Error: delete pathname too short: ", self.filename)
            return False
        elif self.uid() != HostInfo.uid:
            Msg().err("Error: delete not owner: ", self.filename)
            return False
        elif (not force) and (not self._is_safe_prefix(self.filename)):
            Msg().err("Error: delete outside of directory tree: ",
                      self.filename)
            return False
        elif os.path.isfile(self.filename) or os.path.islink(self.filename):
            try:
                os.remove(self.filename)
            except (IOError, OSError):
                Msg().err("Error: deleting file: ", self.filename)
                return False
        elif os.path.isdir(self.filename):
            if recursive:
                status = self._removedir()
            else:
                status = self.rmdir()
            if not status:
                Msg().err("Error: deleting directory: ", self.filename)
                return False
        if self.filename in dict(FileUtil.tmptrash):
            del FileUtil.tmptrash[self.filename]
        return True
def remove ( self , force = False , recursive = False ) : if not os . path . lexists ( self . filename ) : pass elif self . filename . count ( "/" ) < 2 : Msg ( ) . err ( "Error: delete pathname too short: " , self . filename ) return False elif self . uid ( ) != HostInfo . uid : Msg ( ) . err ( "Error: delete not owner: " , self . filename ) return False elif ( not force ) and ( not self . _is_safe_prefix ( self . filename ) ) : Msg ( ) . err ( "Error: delete outside of directory tree: " , self . filename ) return False elif os . path . isfile ( self . filename ) or os . path . islink ( self . filename ) : try : os . remove ( self . filename ) except ( IOError , OSError ) : Msg ( ) . err ( "Error: deleting file: " , self . filename ) return False elif os . path . isdir ( self . filename ) : if recursive : status = self . _removedir ( ) else : status = self . rmdir ( ) if not status : Msg ( ) . err ( "Error: deleting directory: " , self . filename ) return False if self . filename in dict ( FileUtil . tmptrash ) : del FileUtil . tmptrash [ self . filename ] return True