From: Rusty Russell Date: Thu, 14 Aug 2008 05:15:17 +0000 (+1000) Subject: merge X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=41069549813a04a2875063cb12e8057f5d54d7f1;hp=a86b21063f9627872914961b651f97be0aadad12 merge --- diff --git a/ccan/string/test/run-grab.c b/ccan/string/test/run-grab.c new file mode 100644 index 00000000..cfd8b9b4 --- /dev/null +++ b/ccan/string/test/run-grab.c @@ -0,0 +1,25 @@ +/* This is test for grab_file() function */ + +/* + * Example: + * + * void *grab_file(const void *ctx, const char *filename) + * { + * int fd; + * char *buffer; + * + * if (streq(filename, "-")) + * fd = dup(STDIN_FILENO); + * else + * fd = open(filename, O_RDONLY, 0); + * + * if (fd < 0) + * return NULL; + * + * buffer = grab_fd(ctx, fd); + * close_noerr(fd); + * return buffer; + * } + */ + +/* End of grab_file() test */ diff --git a/ccan/string/test/run.c b/ccan/string/test/run.c index 02403d24..f68e7ec5 100644 --- a/ccan/string/test/run.c +++ b/ccan/string/test/run.c @@ -27,6 +27,8 @@ int main(int argc, char *argv[]) char **split, *str; void *ctx; char *strings[NUM_SUBSTRINGS * NUM_SUBSTRINGS]; + int length; + struct stat st; n = 0; for (i = 0; i < NUM_SUBSTRINGS; i++) { @@ -115,7 +117,16 @@ int main(int argc, char *argv[]) ok1(talloc_parent(str) == ctx); talloc_free(ctx); - - + str = grab_file(NULL, "ccan/string/test/run-grab.c"); + split = strsplit(NULL, str, "\n", NULL); + length = strlen(split[0]); + ok1(streq(split[0], "/* This is test for grab_file() function */")); + for(i = 1; split[i]; i++) + length += strlen(split[i]); + ok1(streq(split[i-1], "/* End of grab_file() test */")); + if (stat("ccan/string/test/run-grab.c", &st) != 0) + err(1, "Could not stat self"); + ok1(st.st_size == length); + return exit_status(); } diff --git a/tools/Makefile b/tools/Makefile index 141eb326..a03cc9a4 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -6,7 +6,8 @@ tools/doc_extract: tools/doc_extract.o ccan/string/string.o ccan/noerr/noerr.o c tools/namespacize: tools/namespacize.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o -tools/create_dep_tar: tools/create_dep_tar.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o +tools/create_dep_tar: tools/create_dep_tar.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o tools/_infotojson/sqlite3_database.o tools/_infotojson/utils.o + $(CC) $(LDFLAGS) -o $@ $^ -lsqlite3 tools/run_tests.o tools/namespacize.o tools/depends.o: tools/tools.h diff --git a/tools/create_dep_tar b/tools/create_dep_tar new file mode 100755 index 00000000..7920b0b0 Binary files /dev/null and b/tools/create_dep_tar differ diff --git a/tools/create_dep_tar.c b/tools/create_dep_tar.c index 8247e57e..09c331c6 100644 --- a/tools/create_dep_tar.c +++ b/tools/create_dep_tar.c @@ -3,23 +3,60 @@ #include #include #include +#include #include "ccan/string/string.h" #include "ccan/talloc/talloc.h" +#include "tools/_infotojson/database.h" #define TAR_CMD "tar cvvf " -static void create_tar(char **deps, const char *dir) +/* get dependents of the module from db */ +static char** +get_dependents(const char *dir, const char *db) { - FILE *p; - char *cmd_args, *cmd, *module, *buffer; + char *query, *module, **dependents; + sqlite3 *handle; + int i; + struct db_query *q; + + module = strrchr(dir, '/'); + module++; + + /* getting dependents from db */ + handle = db_open(db); + query = talloc_asprintf(NULL, "select module from search where depends LIKE \"%%%s%%\";", module); + q = db_query(handle, query); + db_close(handle); + + if (q->num_rows == 0) + return 0; + else { + /* getting query results and returning */ + dependents = talloc_array(NULL, char *, q->num_rows + 1); + for (i = 0; i < q->num_rows; i++) + dependents[i] = talloc_asprintf(dependents, "ccan/%s", q->rows[i][0]); + dependents[q->num_rows] = NULL; + return dependents; + } +} + +/* create tar ball of dependencies */ +static void +create_tar(char **deps, const char *dir, const char *targetdir) +{ + FILE *p; + char *cmd_args, *cmd, *module, *buffer; /* getting module name*/ module = strrchr(dir, '/'); module++; - cmd_args = strjoin(NULL, deps, " "); - cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s_dep.tar %s", dir, module, cmd_args); - + if (deps != NULL) { + cmd_args = strjoin(NULL, deps, " "); + cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s_dependencies.tar %s %s", targetdir, module, cmd_args, dir); + } else + cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s.tar %s", targetdir, module, dir); + p = popen(cmd, "r"); if (!p) err(1, "Executing '%s'", cmd); @@ -32,14 +69,34 @@ static void create_tar(char **deps, const char *dir) int main(int argc, char *argv[]) { - char **deps; + char **deps, **dependents; + int i; - if (argc != 2) - errx(1, "Usage: create_dep_tar \n" + if (argc != 4) + errx(1, "Usage: create_dep_tar \n" "Create tar of all the ccan dependencies"); + /* creating tar of the module */ + create_tar(NULL, argv[1], argv[2]); + printf("creating tar ball of \"%s\"\n", argv[1]); + + /* creating tar of the module dependencies */ deps = get_deps(NULL, argv[1]); - if(deps != NULL) - create_tar(deps, argv[1]); + if (deps != NULL) + create_tar(deps, argv[1], argv[2]); + talloc_free(deps); + + /* creating/updating tar of the module dependents */ + dependents = get_dependents(argv[1], argv[3]); + if (dependents != NULL) + for (i = 0; dependents[i]; i++) { + printf("creating tar ball of \"%s\"\n", dependents[i]); + deps = get_deps(NULL, dependents[i]); + if (deps != NULL) + create_tar(deps, dependents[i], argv[2]); + talloc_free(deps); + } + + talloc_free(dependents); return 0; } diff --git a/web/configuration b/web/configuration index 80c6b889..d29bed87 100644 --- a/web/configuration +++ b/web/configuration @@ -9,10 +9,10 @@ $repopath = "testrepo/"; $ccanlint = "tools/ccanlint -d "; //infotojson -$infotojson = "tools/infotojson "; +$infotojson = "../../tools/infotojson "; //create tar of all dependencies -$create_dep_tar = "../tools/create_dep_tar "; +$create_dep_tar = "../../tools/create_dep_tar "; //junk code $junkcode = "junkcode/"; @@ -32,5 +32,15 @@ $frommail = "ccan@ozlabs.org"; //email for admins $ccan_admin = "g.dinesh.cse@gmail.com"; +//ccan home $ccan_home_dir = "ccan/"; + +//bzr clone +$bzr_clone = 'bzr clone /home/dinesh/testwebsite/ '; + +//bzr push +$bzr_push = 'bzr push /home/dinesh/testwebsite/ '; + +//tar home dir +$tar_dir = 'tarball/'; ?> \ No newline at end of file diff --git a/web/db/ccan.db b/web/db/ccan.db index 30078430..77ba6a01 100755 Binary files a/web/db/ccan.db and b/web/db/ccan.db differ diff --git a/web/dispmoduleinfo.php b/web/dispmoduleinfo.php index b6f08172..b0aba20e 100644 --- a/web/dispmoduleinfo.php +++ b/web/dispmoduleinfo.php @@ -8,25 +8,20 @@ $handle = sqlite3_open($db) or die("Could not open database"); $query = "select * from search where module=\"".$_GET['module']."\""; $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle)); $row = sqlite3_fetch_array($result); - -if (!file_exists($repopath . $ccan_home_dir.$_GET['module']."/".$_GET['module'].".tar")) { - chdir($repopath); - exec("tar -cvvf ".$ccan_home_dir. $_GET['module']. "/". $_GET['module'].".tar ". $ccan_home_dir.$_GET['module'], $status); - chdir(".."); -} - -if (!file_exists($repopath . $ccan_home_dir.$_GET['module']."/".$_GET['module']."_dep.tar")) { - chdir($repopath); - exec($create_dep_tar." ".$ccan_home_dir.$_GET['module'], $status); - chdir(".."); -} - - ?> - - +
/.tar>Download/_dep.tar>Download Dependencies + Download'; + ?> + + Download Dependencies'; + ?> +
@@ -42,7 +37,21 @@ if (!file_exists($repopath . $ccan_home_dir.$_GET['module']."/".$_GET['module']. + + + +

Author:

>

Dependencies:

Description:


+ +" . $msg . "Contact ccan admin. "; + exit(); + } +} +?> \ No newline at end of file diff --git a/web/tarball/.tar b/web/tarball/.tar new file mode 100644 index 00000000..54203d2c Binary files /dev/null and b/web/tarball/.tar differ diff --git a/web/uploader.php b/web/uploader.php index 467c51c0..0cb1c184 100644 --- a/web/uploader.php +++ b/web/uploader.php @@ -22,22 +22,12 @@ if($_FILES["uploadedfile"]["type"] == "application/x-gzip" $tempfolder . $_FILES["uploadedfile"]["name"]); //extracting code - if($_FILES["uploadedfile"]["type"] == "application/zip") { + if($_FILES["uploadedfile"]["type"] == "application/zip") exec('unzip '.$tempfolder.$_FILES["uploadedfile"]["name"].' -d '.$tempfolder, $op, $status); - } - else { + else exec('tar -xf '.$tempfolder.$_FILES["uploadedfile"]["name"].' -C '.$tempfolder, $op, $status); - } - checkerror($status[0],"Error: cannot extract(tar error)."); + checkerror($status,"Error: cannot extract(tar error)."); - //chmod - exec('chmod -R 0777 '. $tempfolder.$folder, $status); - checkerror($status[0],"Error: chmod execution error."); - - //running ccanlint - exec($ccanlint.$tempfolder.$folder, $score, $status); - //checkerror($status,"Error: ccanlint execution error."); - //if user not logged in if($_SESSION["slogged"] == false) { //move to temp folder @@ -47,56 +37,107 @@ if($_FILES["uploadedfile"]["type"] == "application/x-gzip" //send mail for review to admins $subject = "Review: code upload at temporary repository"; - $message = "Some developer has uploaded code who has not logged in.\n\nModule is stored in ".$temprepo.$folder.".\n\nOutput of ccanlint: \n"; - foreach($score as $disp) - $message = $message.$disp."\n"; + $message = "Some developer has uploaded code who has not logged in.\n\nModule is stored in ". + $temprepo.$folder.".\n\nOutput of ccanlint: \n"; $toaddress = getccanadmin($db); mail($toaddress, $subject, $message, "From: $frommail"); - echo "
Stored to temporary repository. Mail will be send to admin to get verification of the code."; + echo "
Stored to temporary repository. + Mail will be send to admin to get verification of the code."; unlink($tempfolder.$_FILES["uploadedfile"]["name"]); exit(); } + //running ccanlint + exec($ccanlint.$tempfolder.$folder, $score, $status); + //if not junk code if($status == 0) { $rename = $folder; + $exactpath = $repopath . $_SESSION['susername'] .'/'; + + if (file_exists($exactpath)) { + echo "
Your another upload is in progress please wait...
"; + exit(); + } + + //bzr local repo for commit + chdir($repopath); + unset($op); exec($bzr_clone . $_SESSION['susername'], $op, $status); + checkerror($status, "Error: bzr local repo."); + chdir('..'); + //if module already exist - if (file_exists($repopath.$ccan_home_dir . $folder)) { + if (file_exists($exactpath . $ccan_home_dir . $folder)) { + // if owner is not same - if(!(getowner($repopath.$ccan_home_dir.$folder, $db) == $_SESSION['susername'])) { - if(!file_exists($repopath . $ccan_home_dir. $folder.'-'.$_SESSION['susername'])) - echo "
".$repopath . $ccan_home_dir. $folder . " already exists. Renaming to ". $folder."-".$_SESSION['susername']."
"; + if(!(getowner($ccan_home_dir . $folder, $db) == $_SESSION['susername'])) { + if(!file_exists($repopath . $ccan_home_dir . $folder . '-' . $_SESSION['susername'])) + echo "
". $ccan_home_dir . $folder . + " already exists. Renaming to " . $folder . "-" . $_SESSION['susername'] . "
"; else - echo "
".$repopath . $ccan_home_dir. $folder."-".$_SESSION['susername'] . " already exists. Overwriting ". $folder."-".$_SESSION['susername']."
"; + echo "
". $ccan_home_dir . $folder . + "-" . $_SESSION['susername'] . " already exists. Overwriting " . + $folder. "-" . $_SESSION['susername'] . "
"; $rename = $folder."-".$_SESSION['susername']; } + else - echo "
".$repopath. $ccan_home_dir. $folder. " already exists(uploaded by you). Overwriting ". $repopath. $folder."
"; + echo "
".$repopath. $ccan_home_dir. $folder. + " already exists(uploaded by you). Overwriting ". $repopath. $folder."
"; + } + //module not exist. store author to db else { - storefileowner($repopath . $ccan_home_dir. $folder, $_SESSION['susername'], $db); + storefileowner($ccan_home_dir . $folder, $_SESSION['susername'], $db); } - rmdirr($repopath. $ccan_home_dir. $rename); - rename($tempfolder.$folder, $repopath. $ccan_home_dir. $rename); - echo "
Stored to ".$repopath . $ccan_home_dir. $rename . "
"; + + rmdirr($exactpath . $ccan_home_dir . $rename); + rename($tempfolder . $folder, $exactpath . $ccan_home_dir . $rename); + + chdir($exactpath); + unset($op); exec($infotojson . $ccan_home_dir . $rename . " " . $ccan_home_dir. + $rename."/_info.c ". $ccan_home_dir . $rename . "/json_" . $rename . " " + . $_SESSION['susername']. " ../../" . $db, $op, $status); + checkerror($status,"Error: In infotojson."); + + unset($op); exec('bzr add', $op, $status); + checkerror($status,"Error: bzr add error."); + + unset($op); exec('bzr commit --unchanged -m "commiting from ccan web ' . $rename . + " " . $_SESSION['susername'] . '"', $op, $status); + checkerror($status,"Error: bzr commit error."); + + unset($op); exec($bzr_push, $op, $status); + checkerror($status,"Error: bzr push error."); - exec($infotojson . $repopath. $ccan_home_dir. $rename."/_info.c ". $repopath. $ccan_home_dir. $rename."/json_".$rename. " ". $_SESSION['susername']." ".$db, $status); - checkerror($status[0],"Error: In infotojson."); - //createsearchindex($rename, $repopath.$rename, $infofile, $db, $_SESSION['susername']); + unset($op); exec($create_dep_tar . " " . $ccan_home_dir. $rename . " ../../" . + $tar_dir . " ../../" . $db , $op, $status); + checkerror($status,"Error: bzr push error."); + + chdir('../..'); + rmdirr($exactpath); + echo "
Stored to ". $ccan_home_dir . $rename . "
"; } //if junk code (no _info.c etc) else { + rmdirr($junkcode.$folder.'-'.$_SESSION['susername']); rename($tempfolder.$folder, $junkcode.$folder.'-'.$_SESSION['susername']); + if($score == '') $msg = 'Below is details for test.'; - echo "
Score for code is low. Cannot copy to repository. Moving to ". $junkcode.$folder.'-'.$_SESSION['susername']."...

". $msg ."

"; + + echo "
Score for code is low. + Cannot copy to repository. Moving to ". $junkcode.$folder.'-'. + $_SESSION['susername']."...

". $msg ."

"; + foreach($score as $disp) echo "$disp
"; echo "
"; + } unlink($tempfolder.$_FILES["uploadedfile"]["name"]); }