changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > ventivac / changeset: change vacfs,vacget,vacput to read scores from file.

changeset 77: 0bddab9a6b3a
parent 76: e1b0ad8e7e1f
child 78: 810e5315a6dc
author: Mechiel Lukkien <mechiel@ueber.net>
date: Tue, 17 Jul 2007 23:32:08 +0200
files: appl/cmd/vacfs.b appl/cmd/vacget.b appl/cmd/vacput.b appl/lib/vac.b man/1/vacget man/4/vacfs module/vac.m
description: change vacfs,vacget,vacput to read scores from file.

writing by vacput is still done to standard out, to be redirected to a file to keep the score safe.
     1.1--- a/appl/cmd/vacfs.b	Tue Jul 17 23:04:28 2007 +0200
     1.2+++ b/appl/cmd/vacfs.b	Tue Jul 17 23:32:08 2007 +0200
     1.3@@ -216,7 +216,7 @@
     1.4 	styxservers->init(styx);
     1.5 
     1.6 	arg->init(args);
     1.7-	arg->setusage(arg->progname()+" [-Ddp] [-a addr] [[tag:]score]");
     1.8+	arg->setusage(arg->progname()+" [-Ddp] [-a addr] [vacfile]");
     1.9 	while((ch := arg->opt()) != 0)
    1.10 		case ch {
    1.11 		'D' =>	styxservers->traceset(1);
    1.12@@ -233,17 +233,10 @@
    1.13 
    1.14 	score: ref Score;
    1.15 	if(len args == 1) {
    1.16-		(tag, scorestr) := str->splitstrr(hd args, ":");
    1.17-		if(tag != nil)
    1.18-			tag = tag[:len tag-1];
    1.19-		if(tag == nil)
    1.20-			tag = "vac";
    1.21-		if(tag != "vac")
    1.22-			error("bad score type: "+tag);
    1.23-		(ok, s) := Score.parse(scorestr);
    1.24-		if(ok != 0)
    1.25-			error("bad score: "+scorestr);
    1.26-		score = ref s;
    1.27+		err: string;
    1.28+		(nil, score, err) = vac->readscore(hd args);
    1.29+		if(err != nil)
    1.30+			error("reading score: "+err);
    1.31 	}
    1.32 
    1.33 	(cok, conn) := sys->dial(addr, nil);
     2.1--- a/appl/cmd/vacget.b	Tue Jul 17 23:04:28 2007 +0200
     2.2+++ b/appl/cmd/vacget.b	Tue Jul 17 23:32:08 2007 +0200
     2.3@@ -42,7 +42,7 @@
     2.4 	vac->init();
     2.5 
     2.6 	arg->init(args);
     2.7-	arg->setusage(sprint("%s [-Dptv] [-a addr] [tag:]score", arg->progname()));
     2.8+	arg->setusage(sprint("%s [-Dptv] [-a addr] vacfile", arg->progname()));
     2.9 	while((c := arg->opt()) != 0)
    2.10 		case c {
    2.11 		'a' =>	addr = arg->earg();
    2.12@@ -58,17 +58,9 @@
    2.13 	if(len args != 1)
    2.14 		arg->usage();
    2.15 
    2.16-	(tag, scorestr) := str->splitstrr(hd args, ":");
    2.17-	if(tag != nil)
    2.18-		tag = tag[:len tag-1];
    2.19-	if(tag == nil)
    2.20-		tag = "vac";
    2.21-	if(tag != "vac")
    2.22-		error("bad score type: "+tag);
    2.23-
    2.24-	(sok, score) := Score.parse(scorestr);
    2.25-	if(sok != 0)
    2.26-		error("bad score: "+scorestr);
    2.27+	(nil, score, serr) := vac->readscore(hd args);
    2.28+	if(serr != nil)
    2.29+		error("reading score: "+serr);
    2.30 	say("have score");
    2.31 
    2.32 	(cok, conn) := sys->dial(addr, nil);
    2.33@@ -82,7 +74,7 @@
    2.34 		error(sprint("handshake: %r"));
    2.35 	say("have handshake");
    2.36 
    2.37-	(vd, nil, err) := vac->vdroot(session, score);
    2.38+	(vd, nil, err) := vac->vdroot(session, *score);
    2.39 	if(err != nil)
    2.40 		error(err);
    2.41 
    2.42@@ -134,7 +126,7 @@
    2.43 			warn(sprint("%s: not all bits in mode can be set: 0x%x", newpath, oflags));
    2.44 
    2.45 		if(tflag || vflag)
    2.46-			print("%s\n", newpath);
    2.47+			fprint(fildes(2), "%s\n", newpath);
    2.48 
    2.49 		if(me != nil) {
    2.50 			if(!tflag)
     3.1--- a/appl/cmd/vacput.b	Tue Jul 17 23:04:28 2007 +0200
     3.2+++ b/appl/cmd/vacput.b	Tue Jul 17 23:32:08 2007 +0200
     3.3@@ -34,8 +34,7 @@
     3.4 blocksize := vac->Dsize;
     3.5 session: ref Session;
     3.6 name := "vac";
     3.7-basetag: string;
     3.8-basescore: Score;
     3.9+basescore: ref Score;
    3.10 rcfg: ref Rcfg;
    3.11 blockmin, blockmax: int;
    3.12 
    3.13@@ -64,24 +63,17 @@
    3.14 	blockmax = 32*1024;
    3.15 
    3.16 	arg->init(args);
    3.17-	arg->setusage(sprint("%s [-Dqrv] [-d base] [-a addr] [-b blocksize] [-n name] path ...", arg->progname()));
    3.18+	arg->setusage(sprint("%s [-Dqrv] [-d vacfile] [-a addr] [-b blocksize] [-n name] path ...", arg->progname()));
    3.19 	while((c := arg->opt()) != 0)
    3.20 		case c {
    3.21 		'a' =>	addr = arg->earg();
    3.22 		'b' =>	blocksize = int arg->earg();
    3.23 		'n' =>	name = arg->earg();
    3.24-		'd' =>	(tag, scorestr) := str->splitstrr(arg->earg(), ":");
    3.25-			if(tag != nil)
    3.26-				tag = tag[:len tag-1];
    3.27-			if(tag == nil)
    3.28-				tag = "vac";
    3.29-			if(tag != "vac")
    3.30-				error("bad score type: "+tag);
    3.31-			basetag = tag;
    3.32-			ok: int;
    3.33-			(ok, basescore) = Score.parse(scorestr);
    3.34-			if(ok != 0)
    3.35-				error("bad score: "+scorestr);
    3.36+		'd' =>
    3.37+			err: string;
    3.38+			(nil, basescore, err) = vac->readscore(arg->earg());
    3.39+			if(err != nil)
    3.40+				error("reading score: "+err);
    3.41 		'D' =>	Dflag++;
    3.42 			vac->dflag++;
    3.43 			rabin->debug++;
    3.44@@ -115,13 +107,13 @@
    3.45 	say("have handshake");
    3.46 
    3.47 	vd: ref Vacdir;
    3.48-	if(basetag != nil) {
    3.49+	if(basescore != nil) {
    3.50 		err: string;
    3.51-		(vd, nil, err) = vac->vdroot(session, basescore);
    3.52+		(vd, nil, err) = vac->vdroot(session, *basescore);
    3.53 		if(err != nil)
    3.54 			error("opening base score: "+err);
    3.55 
    3.56-		d := session.read(basescore, Roottype, Rootsize);
    3.57+		d := session.read(*basescore, Roottype, Rootsize);
    3.58 		if(d == nil)
    3.59 			error("reading base root block: "+err);
    3.60 		r := Root.unpack(d);
    3.61@@ -196,7 +188,7 @@
    3.62 writepath(path: string, s: ref Sink, ms: ref MSink, vd: ref Vacdir)
    3.63 {
    3.64 	if(vflag)
    3.65-		print("%s\n", path);
    3.66+		fprint(fildes(2), "%s\n", path);
    3.67 say("writepath "+path);
    3.68 	fd := sys->open(path, sys->OREAD);
    3.69 	if(fd == nil)
     4.1--- a/appl/lib/vac.b	Tue Jul 17 23:04:28 2007 +0200
     4.2+++ b/appl/lib/vac.b	Tue Jul 17 23:32:08 2007 +0200
     4.3@@ -1,10 +1,12 @@
     4.4 implement Vac;
     4.5 
     4.6 include "sys.m";
     4.7+include "string.m";
     4.8 include "venti.m";
     4.9 include "vac.m";
    4.10 
    4.11 sys: Sys;
    4.12+str: String;
    4.13 venti: Venti;
    4.14 
    4.15 werrstr, sprint, fprint, fildes: import sys;
    4.16@@ -35,6 +37,7 @@
    4.17 init()
    4.18 {
    4.19 	sys = load Sys Sys->PATH;
    4.20+	str = load String String->PATH;
    4.21 	venti = load Venti Venti->PATH;
    4.22 	venti->init();
    4.23 }
    4.24@@ -1092,6 +1095,27 @@
    4.25 	return (Vacdir.new(session, e[0], e[1]), de, nil);
    4.26 }
    4.27 
    4.28+readscore(path: string): (string, ref Venti->Score, string)
    4.29+{
    4.30+	f := sys->open(path, Sys->OREAD);
    4.31+	if(f == nil)
    4.32+		return (nil, nil, sprint("open: %r"));
    4.33+	n := sys->read(f, d := array[Rootnamelen+1+2*Scoresize+1] of byte, len d);
    4.34+	if(n < 0)
    4.35+		return (nil, nil, sprint("read: %r"));
    4.36+
    4.37+	(tag, scorestr) := str->splitstrr(string d[:n], ":");
    4.38+	if(tag != nil)
    4.39+		tag = tag[:len tag-1];
    4.40+	if(tag != "vac")
    4.41+		return (nil, nil, "unknown score type: "+tag);
    4.42+	if(len scorestr == 2*Scoresize+1)
    4.43+		scorestr = scorestr[:len scorestr-1];
    4.44+	(ok, s) := Score.parse(scorestr);
    4.45+	if(ok != 0)
    4.46+		return (nil, nil, "bad score: "+scorestr);
    4.47+	return (tag, ref s, nil);
    4.48+}
    4.49 
    4.50 checksize(n: int): int
    4.51 {
     5.1--- a/man/1/vacget	Tue Jul 17 23:04:28 2007 +0200
     5.2+++ b/man/1/vacget	Tue Jul 17 23:32:08 2007 +0200
     5.3@@ -9,7 +9,7 @@
     5.4 .B -a
     5.5 .I addr
     5.6 ]
     5.7-.I vac:score
     5.8+.I vacfile
     5.9 .br
    5.10 .B vacput
    5.11 [
    5.12@@ -22,7 +22,7 @@
    5.13 .I blocksize
    5.14 ] [
    5.15 .B -d
    5.16-.I tag:score
    5.17+.I vacfile
    5.18 ] [
    5.19 .B -n
    5.20 .I name
    5.21@@ -43,9 +43,9 @@
    5.22 .B -q
    5.23 to allow vacput to only write new data in append-only files to venti.
    5.24 .TP
    5.25-.BI -d " tag:score"
    5.26-The archive denoted by
    5.27-.I tag:score
    5.28+.BI -d " vacfile"
    5.29+The score in
    5.30+.I vacfile
    5.31 is used as base archive while writing.  Only the contents of files that have been modified are written to venti before inclusion in the new archive.  Only for vacput.
    5.32 .TP
    5.33 .B -q
    5.34@@ -58,7 +58,7 @@
    5.35 Try to preserve file permissions and owner/group.  Only for vacget.
    5.36 .TP
    5.37 .B -v
    5.38-Be verbose.  Prints file names to standard output as they are being retrieved or written.  Vacput writes the number of bytes and blocks written and read to standard error.
    5.39+Be verbose.  Prints file names to standard error as they are being retrieved or written.  Vacput also writes the number of bytes and blocks written and read.
    5.40 .TP
    5.41 .B -t
    5.42 List files, do not write them.  Only for vacget.
     6.1--- a/man/4/vacfs	Tue Jul 17 23:04:28 2007 +0200
     6.2+++ b/man/4/vacfs	Tue Jul 17 23:32:08 2007 +0200
     6.3@@ -9,13 +9,13 @@
     6.4 .B -a
     6.5 .I addr
     6.6 ]
     6.7-.I [vac:score]
     6.8+.I [vacfile]
     6.9 .SH DESCRIPTION
    6.10 .I Vacfs
    6.11 makes the contents of a venti archive available over styx.  Standard input is used for reading and writing styx messages.
    6.12 If
    6.13-.I score
    6.14-is not specified, vacfs
    6.15+.I vacfile
    6.16+is not specified to read a score from, vacfs
    6.17 serves multiple venti archives.  In this case the root directory lists no files, but walking to a directory
    6.18 .I score
    6.19 opens the venti archive with that score.  Note that the vacfs does not support writing.
     7.1--- a/module/vac.m	Tue Jul 17 23:04:28 2007 +0200
     7.2+++ b/module/vac.m	Tue Jul 17 23:32:08 2007 +0200
     7.3@@ -195,4 +195,5 @@
     7.4 	};
     7.5 
     7.6 	vdroot:	fn(session: ref Venti->Session, score: Venti->Score): (ref Vacdir, ref Direntry, string);
     7.7+	readscore:	fn(path: string): (string, ref Venti->Score, string);
     7.8 };