Skip to content

Commit

Permalink
HIVE-28691: Check if the path exists before deleting in FileUtils#mov…
Browse files Browse the repository at this point in the history
…eToTrash
  • Loading branch information
wecharyu committed Jan 6, 2025
1 parent 799b5cf commit 7c36e1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.hadoop.hive.metastore.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -85,6 +84,10 @@ public static boolean moveToTrash(FileSystem fs, Path f, Configuration conf, boo
LOG.debug("deleting " + f);
boolean result;
try {
if (!fs.exists(f)) {
LOG.info("The path to moveToTrash does not exist: " + f);
return true;
}
if(purge) {
LOG.debug("purge is set to true. Not moving to Trash " + f);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.apache.hadoop.hive.metastore;

import java.io.FileNotFoundException;

import org.apache.hadoop.hive.metastore.utils.FileUtils;
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
import org.slf4j.Logger;
Expand All @@ -41,15 +39,9 @@ public boolean deleteDir(FileSystem fs, Path f, boolean recursive,
if (FileUtils.moveToTrash(fs, f, conf, ifPurge)) {
return true;
}
if (fs.exists(f)) {
throw new MetaException("Unable to delete directory: " + f);
}
return true;
} catch (FileNotFoundException e) {
return true; // ok even if there is not data
} catch (Exception e) {
MetaStoreUtils.throwMetaException(e);
}
return false;
throw new MetaException("Unable to delete directory: " + f);
}
}

0 comments on commit 7c36e1c

Please sign in to comment.