@Nullable @Deprecated public Path getTestrigObject(String networkName, String testrigName, String objectName) { Path testrigDir = getdirSnapshot(networkName, testrigName); Path file = testrigDir.resolve(Paths.get(BfConsts.RELPATH_OUTPUT, objectName)); /* * Check if we got an object name outside of the testrig folder, perhaps because of ".." in the * name; disallow it */ if (!CommonUtil.getCanonicalPath(file).startsWith(CommonUtil.getCanonicalPath(testrigDir))) { throw new BatfishException("Illegal object name: '" + objectName + "'"); } // Check in output then input directories for backward compatibility // Since inputs and outputs used to be stored together, in the testrig dir if (!file.toFile().exists()) { file = testrigDir.resolve(Paths.get(BfConsts.RELPATH_INPUT, objectName)); } if (Files.isRegularFile(file)) { return file; } else if (Files.isDirectory(file)) { Path zipfile = Paths.get(file + ".zip"); if (Files.exists(zipfile)) { CommonUtil.deleteIfExists(zipfile); } ZipUtility.zipFiles(file, zipfile); // TODO: delete the zipfile return zipfile; } return null; }
@Deprecated public void putObject( String networkName, String snapshotName, String objectName, InputStream fileStream) { Path snapshotDir = getdirSnapshot(networkName, snapshotName); Path file = snapshotDir.resolve(objectName); // check if we got an object name outside of the testrig folder, // perhaps because of ".." in the name; disallow it if (!CommonUtil.getCanonicalPath(file).startsWith(CommonUtil.getCanonicalPath(snapshotDir))) { throw new BatfishException("Illegal object name: '" + objectName + "'"); } Path parentFolder = file.getParent(); if (!Files.exists(parentFolder)) { if (!parentFolder.toFile().mkdirs()) { throw new BatfishException("Failed to create directory: '" + parentFolder + "'"); } } else { if (!Files.isDirectory(parentFolder)) { throw new BatfishException(parentFolder + " already exists but is not a folder"); } } CommonUtil.writeStreamToFile(fileStream, file); }