本文整理了Java中org.eclipse.jgit.util.FileUtils.rename()
方法的一些代码示例,展示了FileUtils.rename()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.rename()
方法的具体详情如下:
包路径:org.eclipse.jgit.util.FileUtils
类名称:FileUtils
方法名:rename
[英]Rename a file or folder. If the rename fails and if we are running on a filesystem where it makes sense to repeat a failing rename then repeat the rename operation up to 9 times with 100ms sleep time between two calls. Furthermore if the destination exists and is directory hierarchy with only directories in it, the whole directory hierarchy will be deleted. If the target represents a non-empty directory structure, empty subdirectories within that structure may or may not be deleted even if the method fails. Furthermore if the destination exists and is a file then the file will be deleted and then the rename is retried.
This operation is not atomic.
[中]重命名文件或文件夹。如果重命名失败,并且我们运行的文件系统重复一次失败的重命名是有意义的,那么在两次调用之间的100毫秒睡眠时间内,重复重命名操作最多9次。此外,如果目标存在并且是目录层次结构,其中只有目录,则将删除整个目录层次结构。如果目标代表一个非空目录结构,那么即使该方法失败,该结构中的空子目录也可能会被删除,也可能不会被删除。此外,如果目标存在并且是文件,则将删除该文件,然后重试重命名。
这个操作不是原子的。
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Rename a file or folder. If the rename fails and if we are running on a
* filesystem where it makes sense to repeat a failing rename then repeat
* the rename operation up to 9 times with 100ms sleep time between two
* calls. Furthermore if the destination exists and is directory hierarchy
* with only directories in it, the whole directory hierarchy will be
* deleted. If the target represents a non-empty directory structure, empty
* subdirectories within that structure may or may not be deleted even if
* the method fails. Furthermore if the destination exists and is a file
* then the file will be deleted and then the rename is retried.
* <p>
* This operation is <em>not</em> atomic.
*
* @see FS#retryFailedLockFileCommit()
* @param src
* the old {@code File}
* @param dst
* the new {@code File}
* @throws java.io.IOException
* if the rename has failed
* @since 3.0
*/
public static void rename(File src, File dst)
throws IOException {
rename(src, dst, StandardCopyOption.REPLACE_EXISTING);
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private static boolean rename(File src, File dst) {
try {
FileUtils.rename(src, dst, StandardCopyOption.ATOMIC_MOVE);
return true;
} catch (AtomicMoveNotSupportedException e) {
LOG.error(e.getMessage(), e);
} catch (IOException e) {
// ignore
}
File dir = dst.getParentFile();
if ((dir.exists() || !dir.mkdirs()) && !dir.isDirectory())
return false;
try {
FileUtils.rename(src, dst, StandardCopyOption.ATOMIC_MOVE);
return true;
} catch (IOException e) {
LOG.error(e.getMessage(), e);
return false;
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
db.closeAllPackHandles(realPack);
tmpPack.setReadOnly();
FileUtils.rename(tmpPack, realPack, ATOMIC_MOVE);
FileUtils.rename(tmpIdx, realIdx, ATOMIC_MOVE);
} catch (IOException e) {
File newIdx = new File(
realIdx.getParentFile(), realIdx.getName() + ".new"); //$NON-NLS-1$
try {
FileUtils.rename(tmpIdx, newIdx, ATOMIC_MOVE);
} catch (IOException e2) {
newIdx = tmpIdx;
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Commit this change and release the lock.
* <p>
* If this method fails (returns false) the lock is still released.
*
* @return true if the commit was successful and the file contains the new
* data; false if the commit failed and the file remains with the
* old data.
* @throws java.lang.IllegalStateException
* the lock is not held.
*/
public boolean commit() {
if (os != null) {
unlock();
throw new IllegalStateException(MessageFormat.format(JGitText.get().lockOnNotClosed, ref));
}
saveStatInformation();
try {
FileUtils.rename(lck, ref, StandardCopyOption.ATOMIC_MOVE);
haveLck = false;
closeToken();
return true;
} catch (IOException e) {
unlock();
return false;
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* 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);
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
tmpPack.setReadOnly();
FileUtils.rename(tmpPack, realPack, StandardCopyOption.ATOMIC_MOVE);
for (Map.Entry<PackExt, File> tmpEntry : tmpExts.entrySet()) {
File tmpExt = tmpEntry.getValue();
"." + tmpEntry.getKey().getExtension()); //$NON-NLS-1$
try {
FileUtils.rename(tmpExt, realExt,
StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
realExt.getName() + ".new"); //$NON-NLS-1$
try {
FileUtils.rename(tmpExt, newExt,
StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e2) {
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
FileUtils.rename(tmpPack, finalPack,
StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
FileUtils.rename(tmpIdx, finalIdx, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
cleanupTemporaryFiles();
代码示例来源:origin: berlam/github-bucket
/**
* Rename a file or folder. If the rename fails and if we are running on a
* filesystem where it makes sense to repeat a failing rename then repeat
* the rename operation up to 9 times with 100ms sleep time between two
* calls. Furthermore if the destination exists and is directory hierarchy
* with only directories in it, the whole directory hierarchy will be
* deleted. If the target represents a non-empty directory structure, empty
* subdirectories within that structure may or may not be deleted even if
* the method fails. Furthermore if the destination exists and is a file
* then the file will be deleted and then the rename is retried.
* <p>
* This operation is <em>not</em> atomic.
*
* @see FS#retryFailedLockFileCommit()
* @param src
* the old {@code File}
* @param dst
* the new {@code File}
* @throws java.io.IOException
* if the rename has failed
* @since 3.0
*/
public static void rename(File src, File dst)
throws IOException {
rename(src, dst, StandardCopyOption.REPLACE_EXISTING);
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
FileUtils.delete(f, FileUtils.RECURSIVE);
FileUtils.rename(tmpFile, f, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
throw new IOException(
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
FileUtils.rename(stashLockFile, stashFile,
StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
File dest = getFile(fh.getNewPath(), false);
try {
FileUtils.rename(f, dest,
StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
/**
* Rename a file or folder. If the rename fails and if we are running on a
* filesystem where it makes sense to repeat a failing rename then repeat
* the rename operation up to 9 times with 100ms sleep time between two
* calls. Furthermore if the destination exists and is directory hierarchy
* with only directories in it, the whole directory hierarchy will be
* deleted. If the target represents a non-empty directory structure, empty
* subdirectories within that structure may or may not be deleted even if
* the method fails. Furthermore if the destination exists and is a file
* then the file will be deleted and then the rename is retried.
* <p>
* This operation is <em>not</em> atomic.
*
* @see FS#retryFailedLockFileCommit()
* @param src
* the old {@code File}
* @param dst
* the new {@code File}
* @throws IOException
* if the rename has failed
* @since 3.0
*/
public static void rename(final File src, final File dst)
throws IOException {
rename(src, dst, StandardCopyOption.REPLACE_EXISTING);
}
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
private static boolean rename(File src, File dst) {
try {
FileUtils.rename(src, dst, StandardCopyOption.ATOMIC_MOVE);
return true;
} catch (AtomicMoveNotSupportedException e) {
LOG.error(e.getMessage(), e);
} catch (IOException e) {
// ignore
}
File dir = dst.getParentFile();
if ((dir.exists() || !dir.mkdirs()) && !dir.isDirectory())
return false;
try {
FileUtils.rename(src, dst, StandardCopyOption.ATOMIC_MOVE);
return true;
} catch (IOException e) {
LOG.error(e.getMessage(), e);
return false;
}
}
代码示例来源:origin: berlam/github-bucket
private static boolean rename(File src, File dst) {
try {
FileUtils.rename(src, dst, StandardCopyOption.ATOMIC_MOVE);
return true;
} catch (AtomicMoveNotSupportedException e) {
LOG.error(e.getMessage(), e);
} catch (IOException e) {
// ignore
}
File dir = dst.getParentFile();
if ((dir.exists() || !dir.mkdirs()) && !dir.isDirectory())
return false;
try {
FileUtils.rename(src, dst, StandardCopyOption.ATOMIC_MOVE);
return true;
} catch (IOException e) {
LOG.error(e.getMessage(), e);
return false;
}
}
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
/**
* Commit this change and release the lock.
* <p>
* If this method fails (returns false) the lock is still released.
*
* @return true if the commit was successful and the file contains the new
* data; false if the commit failed and the file remains with the
* old data.
* @throws IllegalStateException
* the lock is not held.
*/
public boolean commit() {
if (os != null) {
unlock();
throw new IllegalStateException(MessageFormat.format(JGitText.get().lockOnNotClosed, ref));
}
saveStatInformation();
try {
FileUtils.rename(lck, ref, StandardCopyOption.ATOMIC_MOVE);
haveLck = false;
return true;
} catch (IOException e) {
unlock();
return false;
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit.lfs
FileUtils.mkdirs(parent.toFile(), true);
FileUtils.rename(tmpFile.toFile(), mediaFile.toFile(),
StandardCopyOption.ATOMIC_MOVE);
代码示例来源:origin: berlam/github-bucket
db.closeAllPackHandles(realPack);
tmpPack.setReadOnly();
FileUtils.rename(tmpPack, realPack, ATOMIC_MOVE);
FileUtils.rename(tmpIdx, realIdx, ATOMIC_MOVE);
} catch (IOException e) {
File newIdx = new File(
realIdx.getParentFile(), realIdx.getName() + ".new"); //$NON-NLS-1$
try {
FileUtils.rename(tmpIdx, newIdx, ATOMIC_MOVE);
} catch (IOException e2) {
newIdx = tmpIdx;
代码示例来源:origin: berlam/github-bucket
/**
* Commit this change and release the lock.
* <p>
* If this method fails (returns false) the lock is still released.
*
* @return true if the commit was successful and the file contains the new
* data; false if the commit failed and the file remains with the
* old data.
* @throws java.lang.IllegalStateException
* the lock is not held.
*/
public boolean commit() {
if (os != null) {
unlock();
throw new IllegalStateException(MessageFormat.format(JGitText.get().lockOnNotClosed, ref));
}
saveStatInformation();
try {
FileUtils.rename(lck, ref, StandardCopyOption.ATOMIC_MOVE);
haveLck = false;
closeToken();
return true;
} catch (IOException e) {
unlock();
return false;
}
}
代码示例来源:origin: berlam/github-bucket
/**
* 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);
}
}
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
File dest = getFile(fh.getNewPath(), false);
try {
FileUtils.rename(f, dest,
StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
内容来源于网络,如有侵权,请联系作者删除!