Skip to content

Commit 90820ac

Browse files
authored
HIVE-28691: Check if the path exists before deleting in FileUtils#moveToTrash (#5596)(Wechar Yu, reviewed by Denys Kuzmenko, Butao Zhang)
1 parent 6c6fb28 commit 90820ac

File tree

2 files changed

+6
-11
lines changed
  • standalone-metastore

2 files changed

+6
-11
lines changed

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/FileUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package org.apache.hadoop.hive.metastore.utils;
1919

20-
import java.io.FileNotFoundException;
2120
import java.io.IOException;
2221
import java.net.URI;
2322
import java.util.ArrayList;
@@ -85,7 +84,11 @@ public static boolean moveToTrash(FileSystem fs, Path f, Configuration conf, boo
8584
LOG.debug("deleting " + f);
8685
boolean result;
8786
try {
88-
if(purge) {
87+
if (!fs.exists(f)) {
88+
LOG.warn("The path to moveToTrash does not exist: " + f);
89+
return true;
90+
}
91+
if (purge) {
8992
LOG.debug("purge is set to true. Not moving to Trash " + f);
9093
} else {
9194
result = Trash.moveToAppropriateTrash(fs, f, conf);

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreFsImpl.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
package org.apache.hadoop.hive.metastore;
2020

21-
import java.io.FileNotFoundException;
22-
2321
import org.apache.hadoop.hive.metastore.utils.FileUtils;
2422
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
2523
import org.slf4j.Logger;
@@ -41,15 +39,9 @@ public boolean deleteDir(FileSystem fs, Path f, boolean recursive,
4139
if (FileUtils.moveToTrash(fs, f, conf, ifPurge)) {
4240
return true;
4341
}
44-
if (fs.exists(f)) {
45-
throw new MetaException("Unable to delete directory: " + f);
46-
}
47-
return true;
48-
} catch (FileNotFoundException e) {
49-
return true; // ok even if there is not data
5042
} catch (Exception e) {
5143
MetaStoreUtils.throwMetaException(e);
5244
}
53-
return false;
45+
throw new MetaException("Unable to delete directory: " + f);
5446
}
5547
}

0 commit comments

Comments
 (0)