diff src/org/tmatesoft/hg/internal/COWTransaction.java @ 621:99ad1e3a4e4d

RevlogStream: be aware of existence (not HgDataFile), facilitate use of an added HgDataFile over a commit; Rollback: be more sensitive about file changes (file size is not enough: write/rollback leaves it intact); tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sat, 18 May 2013 22:23:57 +0200
parents 65c01508f002
children 4ec2d44e2bf3
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/COWTransaction.java	Sat May 18 21:55:31 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/COWTransaction.java	Sat May 18 22:23:57 2013 +0200
@@ -48,7 +48,13 @@
 	public File prepare(File f) throws HgIOException {
 		if (!f.exists()) {
 			record(f, null);
-			return f;
+			try {
+				f.getParentFile().mkdirs();
+				f.createNewFile();
+				return f;
+			} catch (IOException ex) {
+				throw new HgIOException("Failed to create new file", ex, f);
+			}
 		}
 		if (known(f)) {
 			return f;
@@ -123,6 +129,10 @@
 					String msg = String.format("Transaction rollback failed, could not rename backup %s back to %s", e.backup.getName(), e.origin.getName());
 					throw new HgIOException(msg, e.origin);
 				}
+				// renameTo() doesn't update timestamp, while the rest of the code relies
+				// on file timestamp to detect revlog changes. Rollback *is* a change,
+				// even if it brings the old state.
+				e.origin.setLastModified(System.currentTimeMillis());
 			}
 			success.add(e);
 			it.remove();