public static String detectMimeType(File file) { if (file == null || !file.exists()) { return null; } InputStream is = null; try { is = openFileForReading(file); return detectMimeType(is); } catch (IOException e) { return null; } catch (SVNException e) { return null; } finally { closeFile(is); } }
public static File createTmpFile(SVNAdminArea adminArea, String prefix, String suffix, boolean tmp) throws SVNException { StringBuffer buffer = new StringBuffer(); buffer.append(SVNFileUtil.getAdminDirectoryName()); buffer.append('/'); if (tmp) { buffer.append(TMP_DIR_NAME); buffer.append('/'); } String adminPath = buffer.toString(); File dir = adminArea.getFile(adminPath); return SVNFileUtil.createUniqueFile(dir, prefix, suffix, false); }
public void cleanup() { for (File tempFile : tempFiles) { try { SVNFileUtil.deleteFile(tempFile); } catch (SVNException ignore) { } } }
private static void markLogProcessed(File logFile) throws SVNException { SVNFileUtil.setReadonly(logFile, false); OutputStream os = null; try { os = SVNFileUtil.openFileForWriting(logFile); } finally { if (os != null) { SVNFileUtil.closeFile(os); } } }
private boolean attemptDeletion(File parentDir, File baseName) throws SVNException { if (baseName == null) { return false; } File fullPath = SVNFileUtil.createFilePath(parentDir, baseName); return SVNFileUtil.deleteFile(fullPath); }
private static File createTestFile(File tmpDir, String permissions, ISVNReturnValueCallback callback) throws SVNException { File file = SVNFileUtil.createUniqueFile(tmpDir, "svnkit", ".init.jna", false); SVNFileUtil.execCommand(new String[]{SVNFileUtil.getChmodCommand(), permissions, file.getAbsolutePath()}, true, callback); return file; }
public void loadFromRepository() throws SVNException { myBaseFile = SVNFileUtil.createUniqueFile(getTempDirectory(), "diff", ".tmp"); OutputStream os = null; myBaseProperties = new HashMap(); try { os = SVNFileUtil.openFileForWriting(myBaseFile); myRepos.getFile(myRepositoryPath, myRevision1, myBaseProperties, new SVNCancellableOutputStream(os, myCancelHandler)); } finally { SVNFileUtil.closeFile(os); } }
private void storeServerCertificate(String realm, String data, int failures) throws SVNException { myAuthDirectory.mkdirs(); File file = new File(myAuthDirectory, SVNFileUtil.computeChecksum(realm)); SVNHashMap map = new SVNHashMap(); map.put("ascii_cert", data); map.put("svn:realmstring", realm); map.put("failures", Integer.toString(failures)); SVNFileUtil.deleteFile(file); File tmpFile = SVNFileUtil.createUniqueFile(myAuthDirectory, "auth", ".tmp", true); try { SVNWCProperties.setProperties(SVNProperties.wrap(map), file, tmpFile, SVNWCProperties.SVN_HASH_TERMINATOR); } finally { SVNFileUtil.deleteFile(tmpFile); } }
public static void createFormatFile(File adminDir) throws SVNException { OutputStream os = null; try { os = SVNFileUtil.openFileForWriting(new File(adminDir, "format")); os.write(FORMAT_TEXT); } catch (IOException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e.getLocalizedMessage()); SVNErrorManager.error(err, e, SVNLogType.FSFS); } finally { SVNFileUtil.closeFile(os); } }
public void fetchFileContent(OutputStream os) throws SVNException { InputStream is = SVNFileUtil.openFileForReading(path, SVNLogType.WC); try { SVNTranslator.copy(is, os); } catch (IOException e) { SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.IO_ERROR), SVNLogType.DEFAULT); } finally { SVNFileUtil.closeFile(is); } }
public static UniqueFileInfo openUniqueFile(File dirPath, boolean openStream) throws SVNException { UniqueFileInfo info = new UniqueFileInfo(); if (dirPath == null) { dirPath = SVNFileUtil.createFilePath(System.getProperty("java.io.tmpdir")); } info.path = SVNFileUtil.createUniqueFile(dirPath, "svn", ".tmp", false); if (openStream) { info.stream = SVNFileUtil.openFileForWriting(info.path); } return info; }
public InputStream getBaseFileForReading(String name, boolean tmp) throws SVNException { String path = tmp ? "tmp/" : ""; path += "text-base/" + name + ".svn-base"; File baseFile = getAdminFile(path); return SVNFileUtil.openFileForReading(baseFile, SVNLogType.WC); }
public static Map computeAutoProperties(ISVNOptions options, File file, Map properties) throws SVNException { properties = options.applyAutoProperties(file, properties); if (!properties.containsKey(SVNProperty.MIME_TYPE)) { String mimeType = SVNFileUtil.detectMimeType(file, options.getFileExtensionsToMimeTypes()); if (mimeType != null) { properties.put(SVNProperty.MIME_TYPE, mimeType); } } if (SVNProperty.isBinaryMimeType((String) properties.get(SVNProperty.MIME_TYPE))) { properties.remove(SVNProperty.EOL_STYLE); properties.remove(SVNProperty.CHARSET); } if (!properties.containsKey(SVNProperty.EXECUTABLE)) { if (SVNFileUtil.isExecutable(file)) { properties.put(SVNProperty.EXECUTABLE, ""); } } return properties; }
public boolean isAdminDirectory(String name) { return name != null && (SVNFileUtil.isWindows) ? SVNFileUtil.getAdminDirectoryName().equalsIgnoreCase(name) : SVNFileUtil.getAdminDirectoryName().equals(name); }
public void closeFile(String path, String textChecksum) throws SVNException { SVNFileUtil.closeFile(source); SVNFileUtil.closeFile(target); try { SVNFileUtil.deleteFile(currentFileBaton.deltaTarget); } catch (SVNException e) { SVNDebugLog.getDefaultLog().log(SVNLogType.CLIENT, e, Level.ALL); } }
public static String execCommand(String[] commandLine, boolean waitAfterRead, ISVNReturnValueCallback callback) throws SVNException { return execCommand(commandLine, null, waitAfterRead, callback); }
public static String getAdminDirectoryName() { if (ourAdminDirectoryName == null) { String defaultAdminDir = ".svn"; if (getEnvironmentVariable("SVN_ASP_DOT_NET_HACK") != null) { defaultAdminDir = "_svn"; } ourAdminDirectoryName = System.getProperty("svnkit.admindir", System.getProperty("javasvn.admindir", defaultAdminDir)); if (ourAdminDirectoryName == null || "".equals(ourAdminDirectoryName.trim())) { ourAdminDirectoryName = defaultAdminDir; } } return ourAdminDirectoryName; }
public static File getApplicationDataPath() { if (ourAppDataPath != null) { return ourAppDataPath; } // String jnaAppData = SVNJNAUtil.getApplicationDataPath(false); // if (jnaAppData != null) { // ourAppDataPath = new File(jnaAppData); // return ourAppDataPath; // } String envAppData = getEnvironmentVariable("APPDATA"); if (envAppData == null) { // no appdata for that user, fallback to system one. ourAppDataPath = getSystemApplicationDataPath(); } else { ourAppDataPath = new File(envAppData); } return ourAppDataPath; }
public static void truncate(File file, long truncateToSize) throws IOException { RandomAccessFile raf = null; try { raf = openRAFileForWriting(file, false); raf.setLength(truncateToSize); } catch (SVNException e) { throw (IOException) new IOException(e.getMessage()).initCause(e); } finally { closeFile(raf); } }
private File createTempFile(File tempDir) throws SVNException { final File tempFile = SVNFileUtil.createUniqueFile(tempDir, "diff.", ".tmp", true); tempFiles.add(tempFile); return tempFile; }