public static void eraseIndex(User user, String indexName)
     throws SearchLibException, NamingException, IOException {
   if (user != null && !user.isAdmin()) throw new SearchLibException("Operation not permitted");
   File indexDir = getIndexDirectory(indexName);
   Client client = null;
   synchronized (ClientCatalog.class) {
     clientsLock.r.lock();
     try {
       client = CLIENTS.get(indexDir);
     } finally {
       clientsLock.r.unlock();
     }
     if (client != null) {
       client.close();
       client.delete();
     } else FileUtils.deleteDirectory(indexDir);
     if (client != null) {
       clientsLock.w.lock();
       try {
         CLIENTS.remove(client.getDirectory());
       } finally {
         clientsLock.w.unlock();
       }
       PushEvent.eventClientSwitch.publish(client);
     }
   }
 }
 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;
 }
Beispiel #3
0
  public Client() {
    FileWriter file;
    try {
      file = new FileWriter("IPAdresses.txt");
      file.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    getDirectory();
  }
 public static void receive_merge(WebApp webapp, Client client)
     throws SearchLibException, IOException {
   File tempDir = getTempReceiveDir(client);
   File clientDir = client.getDirectory();
   Client newClient = null;
   lockClientDir(clientDir);
   try {
     client.close();
     new ReplicationMerge(tempDir, clientDir);
     newClient =
         ClientFactory.INSTANCE.newClient(
             clientDir, true, true, ClientFactory.INSTANCE.properties.getSilentBackupUrl());
     newClient.writeReplCheck();
   } finally {
     unlockClientDir(clientDir, newClient);
   }
   PushEvent.eventClientSwitch.publish(client);
   FileUtils.deleteDirectory(tempDir);
 }
 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);
 }
 private static void unlockClients(List<Client> clients) {
   if (clients == null) return;
   for (Client client : clients) unlockClientDir(client.getDirectory(), null);
 }
 private static final File getTrashReceiveDir(Client client) {
   File clientDir = client.getDirectory();
   return new File(clientDir.getParentFile(), "._" + clientDir.getName());
 }