/** * * @param downloadDir The download directory where the files will be downloaded to. */ public void setDownloadDir( String downloadDir ) { this.downloadDir = IoUtils.normalizeDirPath(downloadDir); }
private String getBackupDir() { String tempBackupDir = getTempBackupDir(); if (tempBackupDir != null) { return IoUtils.normalizeDirPath(tempBackupDir + backupDirName); } return IoUtils.normalizeDirPath(backupDirPath + backupDirName); }
/** * 1. Replaces any '\\' or '/' characters with the ones for this system * <p> * 2. Appends system specific file separator character at the end if not present * * @param source the directory path * @return the properly formatted directory path */ public static String normalizeDirPath( String source ) { return normalizeDirPath(source, OperatingSystemType.getCurrentOsType()); }
private String normalizePath( boolean isFile, String path ) { if (path == null) { return null; } if (isFile) { path = IoUtils.normalizeFilePath(path); } else { path = IoUtils.normalizeDirPath(path); } return path.replace("//", "/").replace("\\\\", "\\"); }
@PublicAtsApi public FileEnvironmentUnit( String origFileName, String backupDirPath, String backupFileName ) { super(); this.origFileName = origFileName; this.backupDirPath = IoUtils.normalizeDirPath(backupDirPath); this.backupFileName = backupFileName; this.description = "file " + origFileName; }
/** * Constructor * * @param backupFileName the name of the backup file * @param dbConnection database connection * @param dbTables list of database tables to backup * @param environmentHandlerFactory the factory for creating backup and restore handlers */ DatabaseEnvironmentUnit( String backupDirPath, String backupFileName, DbConnection dbConnection, List<DbTable> dbTables, EnvironmentHandlerFactory environmentHandlerFactory ) { this.dbTables = dbTables; this.backupDirPath = IoUtils.normalizeDirPath(backupDirPath); this.backupFileName = backupFileName; this.addLocks = true; this.disableForeignKeys = true; this.includeDeleteStatements = true; this.environmentHandlerFactory = environmentHandlerFactory; setDbConnection(dbConnection); }
@Override public void copyDirectory( String fromDirName, String toDirName, boolean isRecursive, boolean failOnError ) { if (log.isDebugEnabled()) { log.debug("Copy contents of directory '" + fromDirName + "' to '" + toDirName + "'"); } if (fromDirName == null) { throw new IllegalArgumentException("Could not copy directories. The source directory name is null"); } if (toDirName == null) { throw new IllegalArgumentException("Could not copy directories. The target directory name is null"); } if (isRecursive && IoUtils.normalizeDirPath(toDirName).startsWith(IoUtils.normalizeDirPath(fromDirName))) { throw new IllegalArgumentException("Could not copy directories. The target directory is subdirectory of the source one"); } File sourceDir = new File(fromDirName); if (! (sourceDir.exists() && sourceDir.isDirectory())) { throw new FileSystemOperationException("Could not read source directory. Directory named '" + fromDirName + "' does not exist."); } copyDirectoryInternal(sourceDir, new File(toDirName), (String[]) null, isRecursive, failOnError); }
/** * Construct directory unit used for backup or restore * @param origDirName the source directory to be backed up or destination one for restore * @param backupDirPath the target parent directory path * @param backupDirName the directory name of the backup. New name of {@link #origDirName} */ @PublicAtsApi public DirectoryEnvironmentUnit( String origDirName, String backupDirPath, String backupDirName ) { super(); if (OperatingSystemType.getCurrentOsType().isWindows()) { try { // unify dir. paths in order to compare them as strings // as it is used in our implementation to cycle files // getCanonicalPath() is used to convert drive letter (Win) to upper case origDirName = new File(origDirName).getCanonicalPath(); backupDirPath = new File(backupDirPath).getCanonicalPath(); } catch (IOException ex) { // usually should not happen throw new IllegalStateException("Error while trying to get canonical " + "paths of original or backup folder", ex); } } this.origDirName = IoUtils.normalizeDirPath(origDirName); // add trailing slash too this.backupDirPath = IoUtils.normalizeDirPath(backupDirPath); this.backupDirName = backupDirName; this.description = "directory " + origDirName; }
/** * * @param androidHome example: "d:\\android\\android-sdk\\" */ @PublicAtsApi public void setAndroidHome( String androidHome ) { if (androidHome != null) { this.androidHome = androidHome; this.adbLocation = IoUtils.normalizeDirPath(this.androidHome) + "platform-tools/"; String pathToADBExecutable = null; if (this.mobileDeviceUtils.isAdbOnWindows()) { pathToADBExecutable = this.adbLocation + "adb.exe"; } else { pathToADBExecutable = this.adbLocation + "adb"; } if (!isWorkingRemotely && !new File(pathToADBExecutable).exists()) { this.adbLocation = null; } } }
private Set<String> getFileAndDirectoryPathsIndex( File dir ) throws EnvironmentCleanupException { Set<String> fileAndDirectoryPaths = new HashSet<String>(); File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { fileAndDirectoryPaths.add(IoUtils.normalizeDirPath(getFileCanonicalPath(file))); fileAndDirectoryPaths.addAll(getFileAndDirectoryPathsIndex(file)); } else { fileAndDirectoryPaths.add(IoUtils.normalizeFilePath(getFileCanonicalPath(file))); } } } return fileAndDirectoryPaths; }
if (child.isDirectory()) { matchingFiles.add(IoUtils.normalizeDirPath(path)); } else { matchingFiles.add(path);
/** * @return browser download directory (absolute path) */ @PublicAtsApi public String getBrowserDownloadDir() { String downloadDir = null; try { downloadDir = getProperty(PROPERTY_BROWSER_DOWNLOAD_DIR); } catch (NoSuchPropertyException nspe) { log.warn(nspe.getMessage()); } if (downloadDir == null || downloadDir.trim().isEmpty()) { try { downloadDir = new File(AtsSystemProperties.SYSTEM_USER_TEMP_DIR).getCanonicalPath(); setBrowserDownloadDir(downloadDir); } catch (IOException e) { log.error("Can't get canonical path of the system temp directory."); } } return IoUtils.normalizeDirPath(downloadDir); }
final String tempPath = IoUtils.normalizeDirPath(AtsSystemProperties.SYSTEM_USER_TEMP_DIR + "/ats_tmp/"); String agentFolderName = tempPath + "agent_" + String.valueOf(agentZip.lastModified());
/** * Not public * @param tempBackupDir * @throws EnvironmentCleanupException if canonical path could not be retrieved */ public void setTempBackupDir( String tempBackupDir ) throws EnvironmentCleanupException { if (tempBackupDir != null) { if (OperatingSystemType.getCurrentOsType().isWindows()) { // unify dir. paths to compare them as strings. // getCanonicalPath() retunrs logical drive letter (Win) in upper case tempBackupDir = getFileCanonicalPath(new File(tempBackupDir)); } this.tempBackupDir = IoUtils.normalizeDirPath(tempBackupDir); } else { this.tempBackupDir = null; } }
final String tempPath = IoUtils.normalizeDirPath( AtsSystemProperties.SYSTEM_USER_TEMP_DIR + "/ats_tmp/" ) + Thread.currentThread().getName() + "_";
public void open() throws RbvStorageException { //first check if the folder is already open if (isOpen) { throw new MatchableAlreadyOpenException("File system folder is already open"); } try { //get the name of the OS this.osType = this.systemOperations.getOperatingSystemType(); // provide path valid for the target host this.path = IoUtils.normalizeDirPath(path, this.osType); } catch (Exception e) { throw new RbvStorageException("Could not open " + getDescription(), e); } isOpen = true; }
this.home = IoUtils.normalizeDirPath(XmlUtils.getAttribute(sourceNode, AtsProjectConfiguration.NODE_ATTRIBUTE_HOME, ""));
private void backupAllFilesInDirectory( File origDir ) throws EnvironmentCleanupException { File[] files = origDir.listFiles(); if (files == null) { throw new EnvironmentCleanupException("No such directory '" + origDir + "'."); } for (File file : files) { if (file.isDirectory()) { backupAllFilesInDirectory(file); } else { String backupFileName = IoUtils.normalizeFilePath(getFileCanonicalPath(file)); // important that case matches incl. drive letter so origDirName and backupDir // should also come after getCanonicalPath() invocation backupFileName = backupFileName.replace(origDirName, getBackupDir()); new FileEnvironmentUnit(getFileCanonicalPath(file), IoUtils.getFilePath(backupFileName), file.getName()).backup(); } } // if the directory is empty - create the new empty directory in the backup folder if (files.length == 0) { String backupDir = IoUtils.normalizeDirPath(getFileCanonicalPath(origDir)) .replace(origDirName, getBackupDir()); new File(backupDir).mkdirs(); } }
/** * Downloads a file from the specified directory and with the specified file * name, the download will preserve the name of the file * * @param localDir * the local directory to download the file to * @param remoteDir * the remote directory to download from * @param remoteFile * the remote file to download */ @PublicAtsApi public void downloadFile( @Validate( name = "localDir", type = ValidationType.STRING_NOT_EMPTY) String localDir, @Validate( name = "remoteDir", type = ValidationType.STRING_NOT_EMPTY) String remoteDir, @Validate( name = "remoteFile", type = ValidationType.STRING_NOT_EMPTY) String remoteFile ) { // validate input parameters new Validator().validateMethodParameters(new Object[]{ localDir, remoteDir, remoteFile }); // upload the file itself this.client.downloadFile(IoUtils.normalizeDirPath(localDir) + remoteFile, remoteDir, remoteFile); }
/** * Download a file from the specified directory and with the specified file * name * * @param localDir * the local directory to download the file to * @param localFile * the local file that will be created * @param remoteDir * the remote directory to download from * @param remoteFile * the remote file to download */ @PublicAtsApi public void downloadFile( @Validate( name = "localFile", type = ValidationType.STRING_NOT_EMPTY) String localFile, @Validate( name = "localDir", type = ValidationType.STRING_NOT_EMPTY) String localDir, @Validate( name = "remoteDir", type = ValidationType.STRING_NOT_EMPTY) String remoteDir, @Validate( name = "remoteFile", type = ValidationType.STRING_NOT_EMPTY) String remoteFile ) { // validate input parameters new Validator().validateMethodParameters(new Object[]{ localFile, localDir, remoteDir, remoteFile }); // upload the file itself this.client.downloadFile(IoUtils.normalizeDirPath(localDir) + localFile, remoteDir, remoteFile); }