Exemplo 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);
   }
 }
Exemplo 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;
 }
Exemplo 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);
   }
 }
Exemplo n.º 4
0
 public static final Set<ClientCatalogItem> getClientCatalog(User user) throws SearchLibException {
   File[] files =
       StartStopListener.OPENSEARCHSERVER_DATA_FILE.listFiles(
           (FileFilter) DirectoryFileFilter.DIRECTORY);
   Set<ClientCatalogItem> set = new TreeSet<ClientCatalogItem>();
   if (files == null) return null;
   for (File file : files) {
     if (!file.isDirectory()) continue;
     String indexName = file.getName();
     if (!isValidIndexName(indexName)) continue;
     if (user == null || user.hasAnyRole(indexName, Role.GROUP_INDEX))
       set.add(new ClientCatalogItem(indexName));
   }
   return set;
 }
Exemplo n.º 5
0
 public static final void receive_file(
     Client client, String filePath, long lastModified, InputStream is) throws IOException {
   File rootDir = getTempReceiveDir(client);
   File targetFile = new File(rootDir, filePath);
   targetFile.createNewFile();
   FileOutputStream fos = null;
   try {
     fos = new FileOutputStream(targetFile);
     int len;
     byte[] buffer = new byte[131072];
     while ((len = is.read(buffer)) != -1) fos.write(buffer, 0, len);
   } catch (IOException e) {
     throw e;
   } finally {
     IOUtils.close(fos);
   }
   targetFile.setLastModified(lastModified);
 }
Exemplo n.º 6
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();
   }
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
0
 public static final void receive_dir(Client client, String filePath) throws IOException {
   File rootDir = getTempReceiveDir(client);
   File targetFile = new File(rootDir, filePath);
   targetFile.mkdir();
 }
Exemplo n.º 9
0
 public static final void receive_init(Client client) throws IOException, SearchLibException {
   ClientFactory.INSTANCE.properties.checkMaxStorageLimit();
   File rootDir = getTempReceiveDir(client);
   FileUtils.deleteDirectory(rootDir);
   rootDir.mkdir();
 }
Exemplo n.º 10
0
 private static final File getTrashReceiveDir(Client client) {
   File clientDir = client.getDirectory();
   return new File(clientDir.getParentFile(), "._" + clientDir.getName());
 }
Exemplo n.º 11
0
 public static final LastModifiedAndSize getLastModifiedAndSize(String indexName)
     throws SearchLibException {
   File file = getIndexDirectory(indexName);
   if (!file.exists()) return null;
   return new LastModifiedAndSize(file, false);
 }