PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 1ms 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
 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
19package org.apache.hadoop.hive.metastore;
20
21import java.io.FileNotFoundException;
22
23import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
25import org.apache.hadoop.conf.Configuration;
26import org.apache.hadoop.fs.FileSystem;
27import org.apache.hadoop.fs.Path;
28import org.apache.hadoop.fs.Trash;
29import org.apache.hadoop.hive.metastore.api.MetaException;
30
31public class HiveMetaStoreFsImpl implements MetaStoreFS {
32
33  public static final Log LOG = LogFactory
34      .getLog("hive.metastore.hivemetastoressimpl");
35
36  @Override
37  public boolean deleteDir(FileSystem fs, Path f, boolean recursive,
38      Configuration conf) throws MetaException {
39    LOG.info("deleting  " + f);
40
41    // older versions of Hadoop don't have a Trash constructor based on the
42    // Path or FileSystem. So need to achieve this by creating a dummy conf.
43    // this needs to be filtered out based on version
44    Configuration dupConf = new Configuration(conf);
45    FileSystem.setDefaultUri(dupConf, fs.getUri());
46
47    try {
48      Trash trashTmp = new Trash(dupConf);
49      if (trashTmp.moveToTrash(f)) {
50        LOG.info("Moved to trash: " + f);
51        return true;
52      }
53
54      if (fs.delete(f, true)) {
55        LOG.info("Deleted the diretory " + f);
56        return true;
57      }
58
59      if (fs.exists(f)) {
60        throw new MetaException("Unable to delete directory: " + f);
61      }
62    } catch (FileNotFoundException e) {
63      return true; // ok even if there is not data
64    } catch (Exception e) {
65      Warehouse.closeFs(fs);
66      MetaStoreUtils.logAndThrowMetaException(e);
67    }
68    return false;
69  }
70
71}