/** * Constructor used for unit testing and mocking * * @param atsAgent the address of the remote ATS agent where the entity is located on * @param absolutePath the absolute path and name of the entity, e.g. /root/file.ext * @param osType the operating system of the machine */ FilePackage( String atsAgent, String absolutePath, OperatingSystemType osType, FileSystemOperations fileSystemOperations, SystemOperations systemOperations ) { this.atsAgent = atsAgent; this.path = IoUtils.getFilePath(absolutePath); this.name = IoUtils.getFileName(absolutePath); this.osType = osType; this.fileSystemOperations = fileSystemOperations; this.systemOperations = systemOperations; }
protected void createDirIfNotExist( String fileName ) throws EnvironmentCleanupException { String filePath = IoUtils.getFilePath(fileName); File directory = new File(filePath); if (directory != null && !directory.exists()) { if (directory.mkdirs()) { log.info("Directory was created: \"" + filePath + "\"."); } else { throw new EnvironmentCleanupException("Could not create directory: " + getFileCanonicalPath(directory)); } } }
@Override public boolean performMatch( MetaData metaData ) throws RbvException { boolean actualResult = false; if (metaData instanceof FileSystemMetaData) { //get the file from the meta data FilePackage file = ((FileSystemMetaData) metaData).getFilePackage(); String destAbsolutePath = file.getAbsolutePath(); log.info("Actual value is '" + destAbsolutePath + "'"); if (filenameRegex == null) { actualResult = !StringUtils.isNullOrEmpty(destAbsolutePath) && destAbsolutePath.equals(this.path); } else { String fileName = file.getName(); String filePath = IoUtils.getFilePath(destAbsolutePath); Pattern pattern = Pattern.compile(filenameRegex); Matcher matcher = pattern.matcher(fileName); actualResult = !StringUtils.isNullOrEmpty(filePath) && filePath.equals(this.path) && matcher.matches(); } } return actualResult; }
File dirPath = new File(IoUtils.getFilePath(backupFile)); if (!dirPath.exists()) { dirPath.mkdirs();
IoUtils.getFilePath(backupFilePath), IoUtils.getFileName(backupFilePath)).restore(); updateRestoredFlag(fileRestored);
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(); } }
IoUtils.getFilePath(backupFilePath), file.getName()).restore(); updateRestoredFlag(fileRestored);
File dirPath = new File(IoUtils.getFilePath(backupFile)); if (!dirPath.exists()) { dirPath.mkdirs();
String filePath = IoUtils.getFilePath(sourceFile); String fileName = IoUtils.getFileName(sourceFile); if (hidden) {
/** * Constructor * * @param atsAgent the address of the remote ATS agent where the entity is located on * @param absolutePath the absolute path and name of the entity, e.g. /root/file.ext * @param osType the operating system of the machine */ public FilePackage( String atsAgent, String absolutePath, OperatingSystemType osType ) { this.atsAgent = atsAgent; this.path = IoUtils.getFilePath(absolutePath); this.name = IoUtils.getFileName(absolutePath); if (this.atsAgent == null) { this.fileSystemOperations = new FileSystemOperations(); this.systemOperations = new SystemOperations(); } else { this.fileSystemOperations = new FileSystemOperations(this.atsAgent); this.systemOperations = new SystemOperations(this.atsAgent); } if (osType == null) { this.osType = this.systemOperations.getOperatingSystemType(); } else { this.osType = osType; } }