boolean deleteInternal ( String src , INode [ ] inodes , boolean recursive , boolean enforcePermission ) throws IOException { ArrayList < BlockInfo > collectedBlocks = new ArrayList < BlockInfo > ( ) ; INode targetNode = null ; byte [ ] [ ] components = inodes == null ? INodeDirectory . getPathComponents ( src ) : null ; writeLock ( ) ; try { if ( NameNode . stateChangeLog . isDebugEnabled ( ) ) { NameNode . stateChangeLog . debug ( "DIR* NameSystem.delete: " + src ) ; } if ( isInSafeMode ( ) ) { throw new SafeModeException ( "Cannot delete " + src , safeMode ) ; } if ( inodes == null ) { inodes = new INode [ components . length ] ; dir . rootDir . getExistingPathINodes ( components , inodes ) ; } if ( enforcePermission && isPermissionEnabled && isPermissionCheckingEnabled ( inodes ) ) { checkPermission ( src , inodes , false , null , FsAction . WRITE , null , FsAction . ALL ) ; } if ( neverDeletePaths . contains ( src ) ) { NameNode . stateChangeLog . warn ( "DIR* NameSystem.delete: " + " Trying to delete a whitelisted path " + src + " by user " + getCurrentUGI ( ) + " from server " + Server . getRemoteIp ( ) ) ; throw new IOException ( "Deleting a whitelisted directory is not allowed. " + src ) ; } if ( ( ! recursive ) && ( ! dir . isDirEmpty ( inodes [ inodes . length - 1 ] ) ) ) { throw new IOException ( src + " is non empty" ) ; } targetNode = dir . delete ( src , inodes , collectedBlocks , BLOCK_DELETION_INCREMENT ) ; if ( targetNode == null ) { return false ; } } finally { writeUnlock ( ) ; } List < INode > removedINodes = new ArrayList < INode > ( ) ; while ( targetNode . name != null ) { // Interatively Remove blocks collectedBlocks . clear ( ) ; // sleep to make sure that the lock can be grabbed by another thread try { Thread . sleep ( 1 ) ; } catch ( InterruptedException e ) { throw new InterruptedIOException ( e . getMessage ( ) ) ; } writeLock ( ) ; try { int filesRemoved = targetNode . collectSubtreeBlocksAndClear ( collectedBlocks , BLOCK_DELETION_INCREMENT , removedINodes ) ; incrDeletedFileCount ( this , filesRemoved ) ; removeBlocks ( collectedBlocks ) ; // remove from inodeMap dir . removeFromInodeMap ( removedINodes ) ; } finally { writeUnlock ( ) ; } } collectedBlocks . clear ( ) ; removedINodes . clear ( ) ; return true ; }
Remove the indicated filename from the namespace . This may invalidate some blocks that make up the file .