@@ -1317,20 +1317,12 @@ boolean delete(String src, BlocksMapUpdateInfo collectedBlocks,
13171317 if (!deleteAllowed (inodesInPath , src ) ) {
13181318 filesRemoved = -1 ;
13191319 } else {
1320- // Before removing the node, first check if the targetNode is for a
1321- // snapshottable dir with snapshots, or its descendants have
1322- // snapshottable dir with snapshots
1323- final INode targetNode = inodesInPath .getLastINode ();
13241320 List <INodeDirectorySnapshottable > snapshottableDirs =
13251321 new ArrayList <INodeDirectorySnapshottable >();
1326- checkSnapshot (targetNode , snapshottableDirs );
1322+ checkSnapshot (inodesInPath . getLastINode () , snapshottableDirs );
13271323 filesRemoved = unprotectedDelete (inodesInPath , collectedBlocks ,
13281324 removedINodes , now );
1329- if (snapshottableDirs .size () > 0 ) {
1330- // There are some snapshottable directories without snapshots to be
1331- // deleted. Need to update the SnapshotManager.
1332- namesystem .removeSnapshottableDirs (snapshottableDirs );
1333- }
1325+ namesystem .removeSnapshottableDirs (snapshottableDirs );
13341326 }
13351327 } finally {
13361328 writeUnlock ();
@@ -1392,18 +1384,25 @@ boolean isNonEmptyDirectory(String path) throws UnresolvedLinkException {
13921384 * @param src a string representation of a path to an inode
13931385 * @param mtime the time the inode is removed
13941386 * @throws SnapshotAccessControlException if path is in RO snapshot
1395- */
1387+ */
13961388 void unprotectedDelete (String src , long mtime ) throws UnresolvedLinkException ,
1397- QuotaExceededException , SnapshotAccessControlException {
1389+ QuotaExceededException , SnapshotAccessControlException , IOException {
13981390 assert hasWriteLock ();
13991391 BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo ();
14001392 List <INode > removedINodes = new ChunkedArrayList <INode >();
14011393
14021394 final INodesInPath inodesInPath = rootDir .getINodesInPath4Write (
14031395 normalizePath (src ), false );
1404- final long filesRemoved = deleteAllowed (inodesInPath , src ) ?
1405- unprotectedDelete (inodesInPath , collectedBlocks ,
1406- removedINodes , mtime ) : -1 ;
1396+ long filesRemoved = -1 ;
1397+ if (deleteAllowed (inodesInPath , src )) {
1398+ List <INodeDirectorySnapshottable > snapshottableDirs =
1399+ new ArrayList <INodeDirectorySnapshottable >();
1400+ checkSnapshot (inodesInPath .getLastINode (), snapshottableDirs );
1401+ filesRemoved = unprotectedDelete (inodesInPath , collectedBlocks ,
1402+ removedINodes , mtime );
1403+ namesystem .removeSnapshottableDirs (snapshottableDirs );
1404+ }
1405+
14071406 if (filesRemoved >= 0 ) {
14081407 getFSNamesystem ().removePathAndBlocks (src , collectedBlocks ,
14091408 removedINodes );
0 commit comments