Ejemplo n.º 1
0
 public static void receive_abort(Client client) throws IOException {
   File tempDir = getTempReceiveDir(client);
   File trashDir = getTrashReceiveDir(client);
   synchronized (ClientCatalog.class) {
     if (tempDir.exists()) FileUtils.deleteDirectory(tempDir);
     if (trashDir.exists()) FileUtils.deleteDirectory(trashDir);
   }
 }
Ejemplo n.º 2
0
 public static final boolean receive_file_exists(
     Client client, String filePath, long lastModified, long length) throws IOException {
   File existsFile = new File(client.getDirectory(), filePath);
   if (!existsFile.exists()) return false;
   if (existsFile.lastModified() != lastModified) return false;
   if (existsFile.length() != length) return false;
   File rootDir = getTempReceiveDir(client);
   IOUtils.appendLines(new File(rootDir, PATH_TO_MOVE), filePath);
   return true;
 }
Ejemplo n.º 3
0
 public static void createIndex(
     User user, String indexName, TemplateAbstract template, URI remoteURI)
     throws SearchLibException, IOException {
   if (user != null && !user.isAdmin()) throw new SearchLibException("Operation not permitted");
   ClientFactory.INSTANCE.properties.checkMaxIndexNumber();
   if (!isValidIndexName(indexName))
     throw new SearchLibException("The name '" + indexName + "' is not allowed");
   synchronized (ClientCatalog.class) {
     File indexDir = new File(StartStopListener.OPENSEARCHSERVER_DATA_FILE, indexName);
     if (indexDir.exists())
       throw new SearchLibException("directory " + indexName + " already exists");
     template.createIndex(indexDir, remoteURI);
   }
 }
Ejemplo n.º 4
0
 public static void receive_switch(WebApp webapp, Client client)
     throws SearchLibException, NamingException, IOException {
   File trashDir = getTrashReceiveDir(client);
   File clientDir = client.getDirectory();
   if (trashDir.exists()) FileUtils.deleteDirectory(trashDir);
   Client newClient = null;
   List<Client> clientDepends = findDepends(client.getIndexName());
   lockClientDir(clientDir);
   try {
     lockClients(clientDepends);
     closeClients(clientDepends);
     try {
       client.trash(trashDir);
       getTempReceiveDir(client).renameTo(clientDir);
       File pathToMoveFile = new File(clientDir, PATH_TO_MOVE);
       if (pathToMoveFile.exists()) {
         for (String pathToMove : FileUtils.readLines(pathToMoveFile)) {
           File from = new File(trashDir, pathToMove);
           File to = new File(clientDir, pathToMove);
           FileUtils.moveFile(from, to);
         }
         if (!pathToMoveFile.delete())
           throw new IOException("Unable to delete the file: " + pathToMoveFile.getAbsolutePath());
       }
       newClient =
           ClientFactory.INSTANCE.newClient(
               clientDir, true, true, ClientFactory.INSTANCE.properties.getSilentBackupUrl());
       newClient.writeReplCheck();
     } finally {
       unlockClients(clientDepends);
     }
   } finally {
     unlockClientDir(clientDir, newClient);
   }
   PushEvent.eventClientSwitch.publish(client);
   FileUtils.deleteDirectory(trashDir);
 }
Ejemplo n.º 5
0
 public static UserList getUserList() throws SearchLibException {
   usersLock.r.lock();
   try {
     if (userList == null) {
       File userFile = new File(StartStopListener.OPENSEARCHSERVER_DATA_FILE, "users.xml");
       if (userFile.exists()) {
         XPathParser xpp = new XPathParser(userFile);
         userList = UserList.fromXml(xpp, xpp.getNode("/" + UserList.usersElement));
       } else userList = new UserList();
     }
     return userList;
   } catch (ParserConfigurationException e) {
     throw new SearchLibException(e);
   } catch (SAXException e) {
     throw new SearchLibException(e);
   } catch (IOException e) {
     throw new SearchLibException(e);
   } catch (XPathExpressionException e) {
     throw new SearchLibException(e);
   } finally {
     usersLock.r.unlock();
   }
 }
Ejemplo n.º 6
0
 public static final LastModifiedAndSize getLastModifiedAndSize(String indexName)
     throws SearchLibException {
   File file = getIndexDirectory(indexName);
   if (!file.exists()) return null;
   return new LastModifiedAndSize(file, false);
 }