public static String prepareLocalSvnRepo(String sourceDir, String checkoutDir) throws Exception { File sourceDirFile = new File(sourceDir); sourceDirFile.mkdirs(); File local = new File(checkoutDir); if (local.exists()) { FileUtils.delete(local, FileUtils.RECURSIVE); } local.mkdirs(); FileSystemUtils.copyRecursively(sourceDirFile, local); return StringUtils.cleanPath("file:///" + local.getAbsolutePath()); }
/** * Creates the directory named by this abstract pathname, including any * necessary but nonexistent parent directories. Note that if this operation * fails it may have succeeded in creating some of the necessary parent * directories. * * @param d * directory to be created * @throws java.io.IOException * if creation of {@code d} fails. This may occur if {@code d} * did exist when the method was called. This can therefore * cause java.io.IOExceptions during race conditions when * multiple concurrent threads all try to create the same * directory. */ public static void mkdirs(File d) throws IOException { mkdirs(d, false); }
private File getFile(String path, boolean create) throws PatchApplyException { File f = new File(getRepository().getWorkTree(), path); if (create) try { File parent = f.getParentFile(); FileUtils.mkdirs(parent, true); FileUtils.createNewFile(f); } catch (IOException e) { throw new PatchApplyException(MessageFormat.format( JGitText.get().createNewFileFailed, f), e); } return f; }
/** * Deletes old pack file, unless 'preserve-oldpacks' is set, in which case it * moves the pack file to the preserved directory * * @param packFile * @param packName * @param ext * @param deleteOptions * @throws IOException */ private void removeOldPack(File packFile, String packName, PackExt ext, int deleteOptions) throws IOException { if (pconfig != null && pconfig.isPreserveOldPacks()) { File oldPackDir = repo.getObjectDatabase().getPreservedDirectory(); FileUtils.mkdir(oldPackDir, true); String oldPackName = "pack-" + packName + ".old-" + ext.getExtension(); //$NON-NLS-1$ //$NON-NLS-2$ File oldPackFile = new File(oldPackDir, oldPackName); FileUtils.rename(packFile, oldPackFile); } else { FileUtils.delete(packFile, deleteOptions); } }
File f = new File(repo.getWorkTree(), entry.getPathString()); File parentDir = f.getParentFile(); FileUtils.mkdirs(parentDir, true); FS fs = repo.getFS(); WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY); String target = RawParseUtils.decode(bytes); if (deleteRecursive && f.isDirectory()) { FileUtils.delete(f, FileUtils.RECURSIVE); FileUtils.delete(f, FileUtils.RECURSIVE); FileUtils.rename(tmpFile, f, StandardCopyOption.ATOMIC_MOVE); } catch (IOException e) { throw new IOException( } finally { if (tmpFile.exists()) { FileUtils.delete(tmpFile);
JGitText.get().repositoryAlreadyExists, getDirectory())); FileUtils.mkdirs(getDirectory(), true); HideDotFiles hideDotFiles = getConfig().getEnum( ConfigConstants.CONFIG_CORE_SECTION, null, objectDatabase.create(); FileUtils.mkdir(new File(getDirectory(), "branches")); //$NON-NLS-1$ FileUtils.mkdir(new File(getDirectory(), "hooks")); //$NON-NLS-1$ FileUtils.delete(tmp); getFS().createSymLink(tmp, "target"); //$NON-NLS-1$ symLinks = null; FileUtils.delete(tmp); } catch (IOException e) {
@Override public RemoteFile readFileWithMode(String uri, String ref, String path) throws GitAPIException, IOException { File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$ try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir) .setURI(uri).call()) { Repository repo = git.getRepository(); ObjectId refCommitId = sha1(uri, ref); if (refCommitId == null) { throw new InvalidRefNameException(MessageFormat .format(JGitText.get().refNotResolved, ref)); } RevCommit commit = repo.parseCommit(refCommitId); TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree()); // TODO(ifrade): Cope better with big files (e.g. using // InputStream instead of byte[]) return new RemoteFile( tw.getObjectReader().open(tw.getObjectId(0)) .getCachedBytes(Integer.MAX_VALUE), tw.getFileMode(0)); } finally { FileUtils.delete(dir, FileUtils.RECURSIVE); } } }
FileUtils.delete(tmp, FileUtils.RETRY); return InsertLooseObjectResult.EXISTS_LOOSE; FileUtils.delete(tmp, FileUtils.RETRY); return InsertLooseObjectResult.EXISTS_PACKED; FileUtils.delete(tmp, FileUtils.RETRY); return InsertLooseObjectResult.EXISTS_LOOSE; Files.move(FileUtils.toPath(tmp), FileUtils.toPath(dst), StandardCopyOption.ATOMIC_MOVE); dst.setReadOnly(); FileUtils.mkdir(dst.getParentFile(), true); try { Files.move(FileUtils.toPath(tmp), FileUtils.toPath(dst), StandardCopyOption.ATOMIC_MOVE); dst.setReadOnly(); FileUtils.delete(tmp, FileUtils.RETRY); return InsertLooseObjectResult.EXISTS_PACKED; FileUtils.delete(tmp, FileUtils.RETRY); return InsertLooseObjectResult.FAILURE;
/** * Create a symbolic link * * @param path * the path of the symbolic link to create * @param target * the target of the symbolic link * @return the path to the symbolic link * @throws java.io.IOException * @since 4.2 */ public static Path createSymLink(File path, String target) throws IOException { Path nioPath = toPath(path); if (Files.exists(nioPath, LinkOption.NOFOLLOW_LINKS)) { BasicFileAttributes attrs = Files.readAttributes(nioPath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); if (attrs.isRegularFile() || attrs.isSymbolicLink()) { delete(path); } else { delete(path, EMPTY_DIRECTORIES_ONLY | RECURSIVE); } } if (SystemReader.getInstance().isWindows()) { target = target.replace('/', '\\'); } Path nioTarget = toPath(new File(target)); return Files.createSymbolicLink(nioPath, nioTarget); }
FileUtils.rename(tmpPack, finalPack, StandardCopyOption.ATOMIC_MOVE); } catch (IOException e) { FileUtils.rename(tmpIdx, finalIdx, StandardCopyOption.ATOMIC_MOVE); } catch (IOException e) { cleanupTemporaryFiles(); keep.unlock(); if (finalPack.exists()) FileUtils.delete(finalPack); if (finalIdx.exists()) FileUtils.delete(finalIdx); throw err;
try { if (!file.exists()) FileUtils.createNewFile(file); out = new FileOutputStream(file); out.write(getContent());
/** * Check if a file is a symbolic link and read it * * @param path * a {@link java.io.File} object. * @return target of link or null * @throws java.io.IOException * @since 3.0 */ public String readSymLink(File path) throws IOException { return FileUtils.readSymLink(path); }
/** * Create a symbolic link * * @param path * a {@link java.io.File} object. * @param target * target path of the symlink * @throws java.io.IOException * @since 3.0 */ public void createSymLink(File path, String target) throws IOException { FileUtils.createSymLink(path, target); }
/** * @param fs * @param file * @return non null attributes object */ static Attributes getFileAttributesBasic(FS fs, File file) { try { Path nioPath = toPath(file); BasicFileAttributes readAttributes = nioPath .getFileSystem() .provider() .getFileAttributeView(nioPath, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).readAttributes(); Attributes attributes = new Attributes(fs, file, true, readAttributes.isDirectory(), fs.supportsExecute() ? file.canExecute() : false, readAttributes.isSymbolicLink(), readAttributes.isRegularFile(), // readAttributes.creationTime().toMillis(), // readAttributes.lastModifiedTime().toMillis(), readAttributes.isSymbolicLink() ? Constants .encode(readSymLink(file)).length : readAttributes.size()); return attributes; } catch (IOException e) { return new Attributes(file, fs); } }
protected void initRepositoryDir() throws IOException { if(repoDir == null) repoDir = FileUtils.createTempDir(getClass().getSimpleName(), null, null); }
JGitText.get().repositoryAlreadyExists, getDirectory())); FileUtils.mkdirs(getDirectory(), true); HideDotFiles hideDotFiles = getConfig().getEnum( ConfigConstants.CONFIG_CORE_SECTION, null, objectDatabase.create(); FileUtils.mkdir(new File(getDirectory(), "branches")); //$NON-NLS-1$ FileUtils.mkdir(new File(getDirectory(), "hooks")); //$NON-NLS-1$ FileUtils.delete(tmp); getFS().createSymLink(tmp, "target"); //$NON-NLS-1$ symLinks = null; FileUtils.delete(tmp); } catch (IOException e) {
public byte[] readFile(String uri, String ref, String path) throws GitAPIException, IOException { File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$ Repository repo = Git .cloneRepository() .setBare(true) .setDirectory(dir) .setURI(uri) .call() .getRepository(); try { return readFileFromRepo(repo, ref, path); } finally { repo.close(); FileUtils.delete(dir, FileUtils.RECURSIVE); } }