Package org.syncany.util

Examples of org.syncany.util.NormalizedPath


     
      // Assemble file to cache
      File cacheFile = assembleFileToCache(fileVersion2);
     
      // Find target path & folder
      NormalizedPath targetPath = findTargetPath();
      NormalizedPath targetFolder = targetPath.getParent();
     
      // Create folder (if necessary) and move file
      if (!targetFolder.toFile().isDirectory()) {
        targetFolder.toFile().mkdirs();
      }
     
      FileUtils.moveFile(cacheFile, targetPath.toFile());
     
      return new RestoreFileSystemActionResult(targetPath.toFile());
View Full Code Here


      return new RestoreFileSystemActionResult(targetPath.toFile());
    }
  }

  private NormalizedPath findTargetPath() throws Exception {
    NormalizedPath targetPath = null;
   
    if (relativeTargetPath == null) {
      String restoredSuffix = "restored version " + fileVersion2.getVersion();
      targetPath = new NormalizedPath(config.getLocalDir(), fileVersion2.getPath()).withSuffix(restoredSuffix, false);
    }
    else {
      targetPath = new NormalizedPath(config.getLocalDir(), relativeTargetPath);
    }
   
    return targetPath;
  }
View Full Code Here

  protected void setLastModified(FileVersion reconstructedFileVersion, File reconstructedFilesAtFinalLocation) {   
    reconstructedFilesAtFinalLocation.setLastModified(reconstructedFileVersion.getLastModified().getTime());     
  }

  protected void moveToConflictFile(FileVersion targetFileVersion) throws IOException {   
    NormalizedPath targetConflictingFile = new NormalizedPath(config.getLocalDir(), targetFileVersion.getPath());
    moveToConflictFile(targetConflictingFile);
 
View Full Code Here

    }
   
    int attempts = 0;
   
    while (attempts++ < 10) {
      NormalizedPath conflictedCopyPath = null;
     
      try {
        conflictedCopyPath = findConflictFilename(conflictingPath);
        logger.log(Level.INFO, "     - Local version conflicts, moving local file "+conflictingPath+" to "+conflictedCopyPath+" ...");

        if (conflictingPath.toFile().isDirectory()) {
          FileUtils.moveDirectory(conflictingPath.toFile(), conflictedCopyPath.toFile());
        }
        else {
          FileUtils.moveFile(conflictingPath.toFile(), conflictedCopyPath.toFile());
        }
       
        // Success!
        break;
      }
View Full Code Here

      }
    }    
  }
 
  protected File moveFileToFinalLocation(File reconstructedFileInCache, FileVersion targetFileVersion) throws IOException {
    NormalizedPath originalPath = new NormalizedPath(config.getLocalDir(), targetFileVersion.getPath());
    NormalizedPath targetPath = originalPath;
       
    try {
      // Clean filename
      if (targetPath.hasIllegalChars()) {
        targetPath = targetPath.toCreatable("filename conflict", true);
      }

      // Try creating folder
      createFolder(targetPath.getParent());
    }
    catch (Exception e) {
      throw new RuntimeException("What to do here?!");
    }
   
    // Try moving file to final destination
    try {
      FileUtils.moveFile(reconstructedFileInCache, targetPath.toFile());
    }
    catch (FileExistsException e) {
      moveToConflictFile(targetPath);
    }
    catch (Exception e) {
      throw new RuntimeException("What to do here?!");
    }   
   
    return targetPath.toFile();
  }
View Full Code Here

      throw new Exception("Unknown file type: " + reconstructedFileVersion.getType());
    }
  }

  protected void createFolder(FileVersion targetFileVersion) throws Exception {
    NormalizedPath targetDirPath = new NormalizedPath(config.getLocalDir(), targetFileVersion.getPath());
   
    logger.log(Level.INFO, "     - Creating folder at " + targetFileVersion + " ...");
   
    try {
      // Clean filename
      if (targetDirPath.hasIllegalChars()) {
        targetDirPath = targetDirPath.toCreatable("filename conflict", true);
        logger.log(Level.INFO, "     - Had illegal chars, cleaned to "+targetDirPath);
      }

      // Try creating it
      createFolder(targetDirPath);
      setFileAttributes(targetFileVersion, targetDirPath.toFile());
    }
    catch (Exception e) {
      throw new RuntimeException("What to do here?!", e);
    }
  }
View Full Code Here

    EnvironmentUtil.setOperatingSystem(operatingSystem);
   
    // Test 1: For a file called 'A black\white telephone ☎.jpg'
    //         Note: "A black" is NOT a directory, it's part of the filename (invalid on Windows!)   
    String alreadyNormalizedRelativePathFileStr = "Pictures/A black\\white telephone ☎.jpg";
    NormalizedPath normalizedPathFile = new NormalizedPath(null, alreadyNormalizedRelativePathFileStr);
   
    assertEquals("Pictures/A black\\white telephone ☎.jpg", normalizedPathFile.toString());
    assertEquals("Pictures", normalizedPathFile.getParent().toString());

    // Test 2: For directory called 'black\\white telephones ☎'    
    String alreadyNormalizedRelativePathDirStr = "Pictures/black\\white telephones ☎";
    NormalizedPath normalizedPathDir = new NormalizedPath(null, alreadyNormalizedRelativePathDirStr);
   
    assertEquals("Pictures/black\\white telephones ☎", normalizedPathDir.toString());
    assertEquals("Pictures", normalizedPathDir.getParent().toString());
   
    // Test 3: For directory called 'black\\white telephones ☎'    
    String alreadyNormalizedRelativePathFileWithBackslashesDirStr = "Pictures/Black\\White Pictures/Mostly\\Black Pictures/blacky.jpg";
    NormalizedPath normalizedPathWithBackslashesDir = new NormalizedPath(null, alreadyNormalizedRelativePathFileWithBackslashesDirStr);
   
    assertEquals("Pictures/Black\\White Pictures/Mostly\\Black Pictures/blacky.jpg", normalizedPathWithBackslashesDir.toString());
    assertEquals("Pictures/Black\\White Pictures/Mostly\\Black Pictures", normalizedPathWithBackslashesDir.getParent().toString());   
  }
View Full Code Here

 
  @Test
  public void testNameAndParentPathForNormalizedPathsMoreTests() {   
    // Does not depend on OS
   
    assertEquals("", new NormalizedPath(null, "Philipp").getParent().toString());    
  }
View Full Code Here

  @Test
  public void testCreatablizationOnWindows() throws Exception {   
    EnvironmentUtil.setOperatingSystem(OperatingSystem.WINDOWS);
    File root = new File("C:\\Philipp");
   
    assertEquals("Philipp", new NormalizedPath(root, "Philipp").toCreatable("filename conflict", true).toString());
    assertEquals("Philipp", new NormalizedPath(root, "Philipp").toCreatable("filename conflict", true).toString());
    assertEquals("Philipp/image.jpg", new NormalizedPath(root, "Philipp/image.jpg").toCreatable("filename conflict", true).toString());
    assertEquals("Philipp/image", new NormalizedPath(root, "Philipp/image").toCreatable("filename conflict", true).toString());
    assertEquals("Philipp/filewithcolons (filename conflict).txt", new NormalizedPath(root, "Philipp/file:with:colons.txt").toCreatable("filename conflict", true).toString()); // Cannot happen on Windows
    assertEquals("Philipp/filewithbackslashes (filename conflict).txt", new NormalizedPath(root, "Philipp/file\\with\\backslashes.txt").toCreatable("filename conflict", true).toString());
    assertEquals("Philipp/folderwithbackslashes (filename conflict)", new NormalizedPath(root, "Philipp/folder\\with\\backslashes").toCreatable("filename conflict", true).toString());
  }
View Full Code Here

TOP

Related Classes of org.syncany.util.NormalizedPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.