changeset 1083:e7fb974e0c26

add Io checksum and use it for push
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 21 Nov 2016 22:48:43 -0700
parents ece3567d4df5
children aa967fd73b80
files src/luan/modules/IoLuan.java src/luan/modules/host/Hosting.luan
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
diff -r ece3567d4df5 -r e7fb974e0c26 src/luan/modules/IoLuan.java
--- a/src/luan/modules/IoLuan.java	Tue Nov 15 19:19:19 2016 -0700
+++ b/src/luan/modules/IoLuan.java	Mon Nov 21 22:48:43 2016 -0700
@@ -225,6 +225,17 @@
 			}
 		}
 
+		public long checksum() throws IOException, LuanException {
+			long cs = 0;
+			InputStream in = new BufferedInputStream(inputStream());
+			int c;
+			while( (c=in.read()) != -1 ) {
+				cs = 31 * cs + c;
+			}
+			in.close();
+			return cs;
+		}
+
 		public LuanTable table() {
 			LuanTable tbl = new LuanTable();
 			try {
@@ -250,6 +261,9 @@
 				tbl.rawPut( "exists", new LuanJavaFunction(
 					LuanIn.class.getMethod( "exists" ), this
 				) );
+				tbl.rawPut( "checksum", new LuanJavaFunction(
+					LuanIn.class.getMethod( "checksum" ), this
+				) );
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}
diff -r ece3567d4df5 -r e7fb974e0c26 src/luan/modules/host/Hosting.luan
--- a/src/luan/modules/host/Hosting.luan	Tue Nov 15 19:19:19 2016 -0700
+++ b/src/luan/modules/host/Hosting.luan	Mon Nov 21 22:48:43 2016 -0700
@@ -28,7 +28,7 @@
 
 	local function process(there_parent,there,here)
 		if here.is_file() then
-			if there == nil or there.last_modified < here.last_modified() then
+			if there == nil or there.checksum ~= here.checksum() then
 				print("copying "..here.to_string())
 				host.copy_file(domain,password,there_parent.path,here.name(),here.read_binary())
 			end