import org.eclipse.jgit.storage.pack.PackWriter;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
+import org.eclipse.jgit.util.FileUtils;
/**
* Wrapper to make creating test data easier.
}
}
- private void prunePacked(ObjectDirectory odb) {
+ private void prunePacked(ObjectDirectory odb) throws IOException {
for (PackFile p : odb.getPacks()) {
for (MutableEntry e : p)
- odb.fileFor(e.toObjectId()).delete();
+ FileUtils.delete(odb.fileFor(e.toObjectId()));
}
}
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.util.FileUtils;
public class AddCommandTest extends RepositoryTestCase {
DirCache dc = git.add().addFilepattern("a.txt").call();
dc.getEntry(0).getObjectId();
- file.delete();
+ FileUtils.delete(file);
// is supposed to do nothing
dc = git.add().addFilepattern("a.txt").call();
git.commit().setMessage("commit a.txt").call();
dc.getEntry(0).getObjectId();
- file.delete();
+ FileUtils.delete(file);
// is supposed to do nothing
dc = git.add().addFilepattern("a.txt").call();
writer.close();
// file sub/b.txt is deleted
- file2.delete();
+ FileUtils.delete(file2);
git.add().addFilepattern("sub").call();
// change in sub/a.txt is staged
writer.print("modified content");
writer.close();
- file2.delete();
+ FileUtils.delete(file2);
// change in sub/a.txt is staged
// deletion of sub/b.txt is staged
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
+import org.eclipse.jgit.util.FileUtils;
/**
* Tests ignore node behavior on the local filesystem.
assertEntry(F, tracked, ".gitignore");
assertEntry(F, tracked, "out");
- new File(trash, "out").delete();
+ FileUtils.delete(new File(trash, "out"));
writeTrashFile("out/foo", "");
beginWalk();
// rule 11
setupCase(headMap, null, idxMap);
- new File(trash, "foo").delete();
+ assertTrue(new File(trash, "foo").delete());
writeTrashFile("foo", "bar");
db.getIndex().getMembers()[0].forceRecheck();
go();
// rules 21
setupCase(idxMap, mergeMap, idxMap);
- new File(trash, "foo").delete();
+ assertTrue(new File(trash, "foo").delete());
writeTrashFile("foo", "bar");
db.getIndex().getMembers()[0].forceRecheck();
go();
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.treewalk.FileTreeIterator;
+import org.eclipse.jgit.util.FileUtils;
/**
* Base class for most JGit unit tests.
protected void deleteTrashFile(final String name) throws IOException {
File path = new File(db.getWorkTree(), name);
- if (!path.delete())
- throw new IOException("Could not delete file " + path.getPath());
+ FileUtils.delete(path);
}
protected static void checkFile(File f, final String checkData)
}
return actTime;
} finally {
- tmp.delete();
+ FileUtils.delete(tmp);
}
}
}
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.pack.PackWriter;
+import org.eclipse.jgit.util.FileUtils;
public class ConcurrentRepackTest extends RepositoryTestCase {
public void setUp() throws Exception {
touch(begin, files[0].getParentFile());
}
- private static void delete(final File[] list) {
+ private static void delete(final File[] list) throws IOException {
final long begin = list[0].getParentFile().lastModified();
for (final File f : list) {
- f.delete();
+ FileUtils.delete(f);
assertFalse(f + " was removed", f.exists());
}
touch(begin, list[0].getParentFile());
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.RawParseUtils;
public class FileTreeIteratorTest extends RepositoryTestCase {
// Verify it was cached by removing the file and getting it again.
//
- new File(trash, paths[0]).delete();
+ FileUtils.delete(new File(trash, paths[0]));
assertEquals(expect, top.getEntryObjectId());
}
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
rup = repo.updateRef(Constants.HEAD);
rup.link(headName);
}
- deleteRecursive(rebaseDir);
+ FileUtils.delete(rebaseDir, FileUtils.RECURSIVE);
return new RebaseResult(Status.OK);
}
return new RebaseResult(Status.UP_TO_DATE);
}
}
// cleanup the files
- deleteRecursive(rebaseDir);
+ FileUtils.delete(rebaseDir, FileUtils.RECURSIVE);
return new RebaseResult(Status.ABORTED);
} finally {
}
}
- private void deleteRecursive(File fileOrFolder) throws IOException {
- File[] children = fileOrFolder.listFiles();
- if (children != null) {
- for (File child : children)
- deleteRecursive(child);
- }
- if (!fileOrFolder.delete())
- throw new IOException("Could not delete " + fileOrFolder.getPath());
- }
-
private String readFile(File directory, String fileName) throws IOException {
byte[] content = IO.readFully(new File(directory, fileName));
// strip off the last LF
import org.eclipse.jgit.treewalk.WorkingTreeOptions;
import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
/**
* This class handles checking out one or two trees merging with the index. This
}
for (String r : removed) {
File file = new File(repo.getWorkTree(), r);
- file.delete();
+ if (!file.delete())
+ throw new CheckoutConflictException(
+ MessageFormat.format(JGitText.get().cannotDeleteFile,
+ file.getAbsolutePath()));
removeEmptyParents(file);
}
}
if (!tmpFile.renameTo(f)) {
// tried to rename which failed. Let' delete the target file and try
// again
- f.delete();
+ FileUtils.delete(f);
if (!tmpFile.renameTo(f)) {
throw new IOException(MessageFormat.format(
JGitText.get().couldNotWriteFile, tmpFile.getPath(),
import org.eclipse.jgit.storage.file.ReflogReader;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
fos.close();
}
} else {
- mergeMsgFile.delete();
+ FileUtils.delete(mergeMsgFile);
}
}
bos.close();
}
} else {
- mergeHeadFile.delete();
+ FileUtils.delete(mergeHeadFile);
}
}
}
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.NameConflictTreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
+import org.eclipse.jgit.util.FileUtils;
/**
* A three-way merger performing a content-merge if necessary
p = p.getParentFile();
if (p == null || p.isDirectory())
throw new IOException(JGitText.get().cannotCreateDirectory);
- p.delete();
+ FileUtils.delete(p);
if (!f.mkdirs())
throw new IOException(JGitText.get().cannotCreateDirectory);
}
} finally {
is.close();
if (inCore)
- of.delete();
+ FileUtils.delete(of);
}
builder.add(dce);
return true;
@Override
InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId objectId,
- boolean createDuplicate) {
+ boolean createDuplicate) throws IOException {
InsertLooseObjectResult result = wrapped.insertUnpackedObject(tmp,
objectId, createDuplicate);
switch (result) {
AnyObjectId objectId) throws IOException;
abstract InsertLooseObjectResult insertUnpackedObject(File tmp,
- ObjectId id, boolean createDuplicate);
+ ObjectId id, boolean createDuplicate) throws IOException;
abstract FileObjectDatabase newCachedFileObjectDatabase();
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileObjectDatabase.AlternateHandle;
import org.eclipse.jgit.storage.file.FileObjectDatabase.AlternateRepository;
+import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader;
/**
getFS().setExecute(tmp, false);
final boolean off = getFS().canExecute(tmp);
- tmp.delete();
+ FileUtils.delete(tmp);
fileMode = on && !off;
} else {
import org.eclipse.jgit.storage.pack.ObjectToPack;
import org.eclipse.jgit.storage.pack.PackWriter;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
/**
* Traditional file system based {@link ObjectDatabase}.
@Override
InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId id,
- boolean createDuplicate) {
+ boolean createDuplicate) throws IOException {
// If the object is already in the repository, remove temporary file.
//
if (unpackedObjectCache.isUnpacked(id)) {
- tmp.delete();
+ FileUtils.delete(tmp);
return InsertLooseObjectResult.EXISTS_LOOSE;
}
if (!createDuplicate && has(id)) {
- tmp.delete();
+ FileUtils.delete(tmp);
return InsertLooseObjectResult.EXISTS_PACKED;
}
// that already exists. We can't be sure renameTo() would
// fail on all platforms if dst exists, so we check first.
//
- tmp.delete();
+ FileUtils.delete(tmp);
return InsertLooseObjectResult.EXISTS_LOOSE;
}
if (tmp.renameTo(dst)) {
}
if (!createDuplicate && has(id)) {
- tmp.delete();
+ FileUtils.delete(tmp);
return InsertLooseObjectResult.EXISTS_PACKED;
}
// either. We really don't know what went wrong, so
// fail.
//
- tmp.delete();
+ FileUtils.delete(tmp);
return InsertLooseObjectResult.FAILURE;
}
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.util.FileUtils;
/** Creates loose objects in a {@link ObjectDirectory}. */
class ObjectDirectoryInserter extends ObjectInserter {
return tmp;
} finally {
if (delete)
- tmp.delete();
+ FileUtils.delete(tmp);
}
}
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
/** Keeps track of a {@link PackFile}'s associated <code>.keep</code> file. */
public class PackLock {
return lf.commit();
}
- /** Remove the <code>.keep</code> file that holds this pack in place. */
- public void unlock() {
- keepFile.delete();
+ /**
+ * Remove the <code>.keep</code> file that holds this pack in place.
+ *
+ * @throws IOException
+ * if deletion of .keep file failed
+ */
+ public void unlock() throws IOException {
+ FileUtils.delete(keepFile);
}
}
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.util.FileUtils;
/**
* Rename any reference stored by {@link RefDirectory}.
try {
refdb.delete(tmp);
} catch (IOException err) {
- refdb.fileFor(tmp.getName()).delete();
+ FileUtils.delete(refdb.fileFor(tmp.getName()));
}
rw.release();
}
try {
executeImp(monitor, result);
} finally {
+ try {
for (final PackLock lock : packLocks)
lock.unlock();
+ } catch (IOException e) {
+ throw new TransportException(e.getMessage(), e);
+ }
}
}
import org.eclipse.jgit.storage.file.PackIndexWriter;
import org.eclipse.jgit.storage.file.PackLock;
import org.eclipse.jgit.storage.pack.BinaryDelta;
+import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.NB;
/** Indexes Git pack files for local use. */
}
} catch (IOException err) {
if (dstPack != null)
- dstPack.delete();
+ FileUtils.delete(dstPack);
if (dstIdx != null)
- dstIdx.delete();
+ FileUtils.delete(dstIdx);
throw err;
}
}
repo.openPack(finalPack, finalIdx);
} catch (IOException err) {
keep.unlock();
- finalPack.delete();
- finalIdx.delete();
+ FileUtils.delete(finalPack);
+ FileUtils.delete(finalIdx);
throw err;
}
}
}
- private void unlockPack() {
+ private void unlockPack() throws IOException {
if (packLock != null) {
packLock.unlock();
packLock = null;
import org.eclipse.jgit.storage.file.PackLock;
import org.eclipse.jgit.storage.file.UnpackedObject;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.util.FileUtils;
/**
* Generic fetch support for dumb transport protocols.
// it failed the index and pack are unusable and we
// shouldn't consult them again.
//
- if (pack.tmpIdx != null)
- pack.tmpIdx.delete();
+ try {
+ if (pack.tmpIdx != null)
+ FileUtils.delete(pack.tmpIdx);
+ } catch (IOException e) {
+ throw new TransportException(e.getMessage(), e);
+ }
packItr.remove();
}
fos.close();
}
} catch (IOException err) {
- tmpIdx.delete();
+ FileUtils.delete(tmpIdx);
throw err;
} finally {
s.in.close();
pm.endTask();
if (pm.isCancelled()) {
- tmpIdx.delete();
+ FileUtils.delete(tmpIdx);
return;
}
try {
index = PackIndex.open(tmpIdx);
} catch (IOException e) {
- tmpIdx.delete();
+ FileUtils.delete(tmpIdx);
throw e;
}
}