Change-Id: Id65dc94c970ffd3ca3d3d4a5d57123c95d29e8af Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>tags/v5.0.0.201806131550-r
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static org.eclipse.jgit.junit.Assert.assertEquals; | import static org.eclipse.jgit.junit.Assert.assertEquals; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
// Check that the involved refs are the same despite the failure | // Check that the involved refs are the same despite the failure | ||||
assertExists(false, toName); | assertExists(false, toName); | ||||
if (!toLock.equals(toName)) | if (!toLock.equals(toName)) | ||||
assertExists(false, toName + ".lock"); | |||||
assertExists(true, toLock + ".lock"); | |||||
assertExists(false, toName + LOCK_SUFFIX); | |||||
assertExists(true, toLock + LOCK_SUFFIX); | |||||
if (!toLock.equals(fromName)) | if (!toLock.equals(fromName)) | ||||
assertExists(false, "logs/" + fromName + ".lock"); | |||||
assertExists(false, "logs/" + toName + ".lock"); | |||||
assertExists(false, "logs/" + fromName + LOCK_SUFFIX); | |||||
assertExists(false, "logs/" + toName + LOCK_SUFFIX); | |||||
assertEquals(oldHeadId, db.resolve(Constants.HEAD)); | assertEquals(oldHeadId, db.resolve(Constants.HEAD)); | ||||
assertEquals(oldfromId, db.resolve(fromName)); | assertEquals(oldfromId, db.resolve(fromName)); | ||||
assertNull(db.resolve(toName)); | assertNull(db.resolve(toName)); |
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
* name. | * name. | ||||
*/ | */ | ||||
public class LockFile { | public class LockFile { | ||||
static final String SUFFIX = ".lock"; //$NON-NLS-1$ | |||||
/** | /** | ||||
* Unlock the given file. | * Unlock the given file. | ||||
* @return lock file | * @return lock file | ||||
*/ | */ | ||||
static File getLockFile(File file) { | static File getLockFile(File file) { | ||||
return new File(file.getParentFile(), file.getName() + SUFFIX); | |||||
return new File(file.getParentFile(), | |||||
file.getName() + LOCK_SUFFIX); | |||||
} | } | ||||
/** Filter to skip over active lock files when listing a directory. */ | /** Filter to skip over active lock files when listing a directory. */ | ||||
static final FilenameFilter FILTER = new FilenameFilter() { | static final FilenameFilter FILTER = new FilenameFilter() { | ||||
@Override | @Override | ||||
public boolean accept(File dir, String name) { | public boolean accept(File dir, String name) { | ||||
return !name.endsWith(SUFFIX); | |||||
return !name.endsWith(LOCK_SUFFIX); | |||||
} | } | ||||
}; | }; | ||||
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static org.eclipse.jgit.lib.Constants.HEAD; | import static org.eclipse.jgit.lib.Constants.HEAD; | ||||
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; | |||||
import static org.eclipse.jgit.lib.Constants.R_HEADS; | import static org.eclipse.jgit.lib.Constants.R_HEADS; | ||||
import static org.eclipse.jgit.lib.Constants.R_NOTES; | import static org.eclipse.jgit.lib.Constants.R_NOTES; | ||||
import static org.eclipse.jgit.lib.Constants.R_REFS; | import static org.eclipse.jgit.lib.Constants.R_REFS; | ||||
* @return the name of the ref's lock ref. | * @return the name of the ref's lock ref. | ||||
*/ | */ | ||||
public static String refLockFor(String name) { | public static String refLockFor(String name) { | ||||
return name + LockFile.SUFFIX; | |||||
return name + LOCK_SUFFIX; | |||||
} | } | ||||
private final RefDirectory refdb; | private final RefDirectory refdb; |
public static final ObjectId EMPTY_BLOB_ID = ObjectId | public static final ObjectId EMPTY_BLOB_ID = ObjectId | ||||
.fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); | .fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); | ||||
/** | |||||
* Suffix of lock file name | |||||
* | |||||
* @since 5.0 | |||||
*/ | |||||
public static final String LOCK_SUFFIX = ".lock"; //$NON-NLS-1$ | |||||
private Constants() { | private Constants() { | ||||
// Hide the default constructor | // Hide the default constructor | ||||
} | } |
package org.eclipse.jgit.lib; | package org.eclipse.jgit.lib; | ||||
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; | |||||
import java.io.BufferedOutputStream; | import java.io.BufferedOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
*/ | */ | ||||
public static boolean isValidRefName(String refName) { | public static boolean isValidRefName(String refName) { | ||||
final int len = refName.length(); | final int len = refName.length(); | ||||
if (len == 0) | |||||
if (len == 0) { | |||||
return false; | return false; | ||||
if (refName.endsWith(".lock")) //$NON-NLS-1$ | |||||
} | |||||
if (refName.endsWith(LOCK_SUFFIX)) { | |||||
return false; | return false; | ||||
} | |||||
// Refs may be stored as loose files so invalid paths | // Refs may be stored as loose files so invalid paths | ||||
// on the local system must also be invalid refs. | // on the local system must also be invalid refs. |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
@Override | @Override | ||||
void writeFile(String path, byte[] data) throws IOException { | void writeFile(String path, byte[] data) throws IOException { | ||||
final String lock = path + ".lock"; //$NON-NLS-1$ | |||||
final String lock = path + LOCK_SUFFIX; | |||||
try { | try { | ||||
super.writeFile(lock, data); | super.writeFile(lock, data); | ||||
try { | try { |