cpack_repository/commit

Make back-link after reload and keep track of file-sizes

authorJan Wielemaker
Thu Nov 18 16:09:27 2010 +0100
committerJan Wielemaker
Thu Nov 18 16:09:27 2010 +0100
commit2718dbbd62ae8c7b68ab9075d2138d42ad6a507d
treead759853aca4da3c9914812329c57dd9e60a6e21
parentad165f1839478388a1d8cf9a6e078488f4acba24
Diff style: patch stat
diff --git a/applications/cpack_submit.pl b/applications/cpack_submit.pl
index de513e7..6755519 100644
--- a/applications/cpack_submit.pl
+++ b/applications/cpack_submit.pl
@@ -120,7 +120,11 @@ cpack_resubmit(Request) :-
 	http_parameters(Request,
 			[ pack(Pack,
 			       [ description('URI of the CPACK to update')
-			       ])
+			       ]),
+			  return_to(ReturnTo,
+				    [ optional(true),
+				      description('Return link')
+				    ])
 			]),
 	rdf_has(Pack, cpack:clonedRepository, GitRepo),
 	rdf_has(GitRepo, cpack:gitURL, GitURL),
@@ -130,10 +134,14 @@ cpack_resubmit(Request) :-
 	),
 	authorized(write(cpack, GitURL)),
 	user_property(User, url(UserURL)),
+	(   var(ReturnTo)
+	->  MsgOptions = []
+	;   MsgOptions = [return_to(ReturnTo)]
+	),
 	call_showing_messages(cpack_add_repository(UserURL, GitURL,
 						   [ branch(Branch)
 						   ]),
-			      []).
+			      MsgOptions).
 
 
 %%	cpack_list_packages(+Request) is det.
diff --git a/components/cpack.pl b/components/cpack.pl
index aa59da4..4da2980 100644
--- a/components/cpack.pl
+++ b/components/cpack.pl
@@ -415,7 +415,13 @@ cpack_update_icon(Pack) -->
 	  user_property(User, url(UserURI)),
 	  rdf_has(Pack, cpack:submittedBy, UserURI),
 	  http_absolute_location(icons('webdev-arrow-up-icon.png'), IMG, []),
-	  http_link_to_id(cpack_resubmit, [pack(Pack)], Resubmit)
+	  http_current_request(Request),
+	  memberchk(request_uri(ReturnTo), Request),
+	  http_link_to_id(cpack_resubmit,
+			  [ pack(Pack),
+			    return_to(ReturnTo)
+			  ],
+			  Resubmit)
 	},
 	html(a(href(Resubmit),
 	       img([ class(update),
diff --git a/lib/cpack/repository.pl b/lib/cpack/repository.pl
index c3d1a31..53643b4 100644
--- a/lib/cpack/repository.pl
+++ b/lib/cpack/repository.pl
@@ -142,7 +142,8 @@ update_allowed(_, Package, _) :-
 update_metadata(BareGitPath, Graph, Options) :-
 	rdf_retractall(_,_,_,Graph),
 	add_files(BareGitPath, Graph, Options),
-	load_meta_data(BareGitPath, Graph, Options),
+	catch(load_meta_data(BareGitPath, Graph, Options), E,
+	      print_message(error, E)),
 	update_decription(BareGitPath, Graph),
 	add_timestamp(Graph),
 	(   option(cloned(ClonedURL), Options)
@@ -174,12 +175,13 @@ add_timestamp(Graph) :-
 		   literal(type(xsd:dateTime, DateTime)), Graph).
 
 update_decription(BareGitPath, Graph) :-
-	rdf_has(Graph, dcterms:title, Literal),
+	rdf_has(Graph, dcterms:title, Literal), !,
 	literal_text(Literal, Title),
 	directory_file_path(BareGitPath, description, DescFile),
 	setup_call_cleanup(open(DescFile, write, Out),
 			   format(Out, '~w~n', [Title]),
 			   close(Out)).
+update_decription(_, _).
 
 %%	git_export(+BareGitPath, -MirroredURL) is det.
 %
@@ -224,7 +226,7 @@ read_to_atom(Hash, In) :-
 
 add_files(BareGitPath, Graph, Options) :-
 	option(branch(Branch), Options, master),
-	git_process_output(['ls-tree', '-r', '--name-only', Branch],
+	git_process_output(['ls-tree', '-lr', Branch],
 			   read_files(Graph),
 			   [directory(BareGitPath)]).
 
@@ -234,7 +236,8 @@ read_files(Graph, In) :-
 
 read_files(end_of_file, _, _) :- !.
 read_files(Line, Graph, In) :-
-	atom_codes(FileName, Line),
+	phrase(file_l(_Mode, _Type, _Hash, Size, FileName), Line),
+	atom_number(SizeAtom, Size),
 	file_base_name(FileName, BaseName),
 	file_base(FileName , BaseID),
 	file_type(BaseName, Class),
@@ -242,6 +245,7 @@ read_files(Line, Graph, In) :-
 	rdf_assert(File, cpack:path, literal(FileName), Graph),
 	rdf_assert(File, cpack:name, literal(BaseName), Graph),
 	rdf_assert(File, cpack:base, literal(BaseID), Graph),
+	rdf_assert(File, cpack:size, literal(type(xsd:integer, SizeAtom)), Graph),
 	rdf_assert(File, cpack:inPack, Graph, Graph),
 	rdf_assert(File, rdf:type, Class, Graph),
 	read_line_to_codes(In, Line2),
@@ -251,6 +255,18 @@ file_base(Path, Base) :-
 	file_base_name(Path, File),
 	file_name_extension(Base, _Ext, File).
 
+file_l(Mode, Type, Hash, Size, Name) -->
+	string_without(" ", MCodes), blanks,
+	string_without(" ", TCodes), blanks,
+	string_without(" ", HCodes), blanks,
+	integer(Size), blanks,
+	string_without(" \n", NCodes), blanks,
+	{ number_codes(Mode, [0'0, 0'o|MCodes]),
+	  atom_codes(Type, TCodes),
+	  atom_codes(Hash, HCodes),
+	  atom_codes(Name, NCodes)
+	}.
+
 
 :- rdf_meta
 	file_type(+, r).
diff --git a/rdf/cpack/cpack_repository.ttl b/rdf/cpack/cpack_repository.ttl
index b44b51d..5eb3d0a 100644
--- a/rdf/cpack/cpack_repository.ttl
+++ b/rdf/cpack/cpack_repository.ttl
@@ -1,5 +1,6 @@
 @prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
 @prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
 @prefix cpack:   <http://www.swi-prolog.org/cliopatria/cpack#> .
 @prefix dcterms: <http://purl.org/dc/terms/> .