diff src/goodjava/lucene/backup/Backup.java @ 1508:86c5e7000ecf

lucene.backup checksum
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 16 May 2020 17:56:02 -0600
parents e66e3d50b289
children 0ba144491a42
line wrap: on
line diff
--- a/src/goodjava/lucene/backup/Backup.java	Sat May 16 12:33:41 2020 +0300
+++ b/src/goodjava/lucene/backup/Backup.java	Sat May 16 17:56:02 2020 -0600
@@ -45,6 +45,8 @@
 		} else if( call.cmd.equals("add") || call.cmd.equals("append")  ) {
 			fileName = (String)call.args[2];
 			File f = new File(dir,fileName);
+			if( call.cmd.equals("add") )
+				IoUtils.delete(f);
 			LogFile log = new LogFile(f);
 			LogOutputStream out = log.output();
 			IoUtils.copyAll(call.in,out);
@@ -78,6 +80,15 @@
 				result = new RpcResult("incomplete",name,logEnd);
 				break;
 			}
+			Object checksumObj = fileInfo.get("checksum");
+			if( checksumObj != null ) {
+				long checksum = (Long)checksumObj;
+				if( log.checksum() != checksum ) {
+					index.delete();
+					result = new RpcResult("bad_checksum",name);
+					break;
+				}
+			}
 		}
 		if( call.cmd.equals("add") ) {
 			boolean complete = true;