PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreFsImpl.java

#
Java | 71 lines | 40 code | 11 blank | 20 comment | 3 complexity | 097785a2f3f9b5cd97b7ca4108a9905c MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.hive.metastore;
  19. import java.io.FileNotFoundException;
  20. import org.apache.commons.logging.Log;
  21. import org.apache.commons.logging.LogFactory;
  22. import org.apache.hadoop.conf.Configuration;
  23. import org.apache.hadoop.fs.FileSystem;
  24. import org.apache.hadoop.fs.Path;
  25. import org.apache.hadoop.fs.Trash;
  26. import org.apache.hadoop.hive.metastore.api.MetaException;
  27. public class HiveMetaStoreFsImpl implements MetaStoreFS {
  28. public static final Log LOG = LogFactory
  29. .getLog("hive.metastore.hivemetastoressimpl");
  30. @Override
  31. public boolean deleteDir(FileSystem fs, Path f, boolean recursive,
  32. Configuration conf) throws MetaException {
  33. LOG.info("deleting " + f);
  34. // older versions of Hadoop don't have a Trash constructor based on the
  35. // Path or FileSystem. So need to achieve this by creating a dummy conf.
  36. // this needs to be filtered out based on version
  37. Configuration dupConf = new Configuration(conf);
  38. FileSystem.setDefaultUri(dupConf, fs.getUri());
  39. try {
  40. Trash trashTmp = new Trash(dupConf);
  41. if (trashTmp.moveToTrash(f)) {
  42. LOG.info("Moved to trash: " + f);
  43. return true;
  44. }
  45. if (fs.delete(f, true)) {
  46. LOG.info("Deleted the diretory " + f);
  47. return true;
  48. }
  49. if (fs.exists(f)) {
  50. throw new MetaException("Unable to delete directory: " + f);
  51. }
  52. } catch (FileNotFoundException e) {
  53. return true; // ok even if there is not data
  54. } catch (Exception e) {
  55. Warehouse.closeFs(fs);
  56. MetaStoreUtils.logAndThrowMetaException(e);
  57. }
  58. return false;
  59. }
  60. }