diff options
author | onefang | 2021-10-08 00:24:09 +1000 |
---|---|---|
committer | onefang | 2021-10-08 00:24:09 +1000 |
commit | 504da13ea8572883eb798f2a536b02b3794eaa11 (patch) | |
tree | 1bf5544a9b4aaf9bf14a556ebc71522c6046df04 | |
parent | Refactor GITAR, so we can call it direct from BACKUP. (diff) | |
download | opensim-SC-504da13ea8572883eb798f2a536b02b3794eaa11.zip opensim-SC-504da13ea8572883eb798f2a536b02b3794eaa11.tar.gz opensim-SC-504da13ea8572883eb798f2a536b02b3794eaa11.tar.bz2 opensim-SC-504da13ea8572883eb798f2a536b02b3794eaa11.tar.xz |
Add UNGITAR.
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 148 |
1 files changed, 146 insertions, 2 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index b74e419..ed84ada 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c | |||
@@ -39,6 +39,12 @@ config SLEDJCHISL | |||
39 | gitar Welcome.shini | 39 | gitar Welcome.shini |
40 | gitar "Welcome sim" | 40 | gitar "Welcome sim" |
41 | Build a gitAR. | 41 | Build a gitAR. |
42 | ungitar -m "Joan Smith" | ||
43 | ungitar Welcome | ||
44 | ungitar Welcome.ini | ||
45 | ungitar Welcome.shini | ||
46 | ungitar "Welcome sim" | ||
47 | Unpack a gitAR into separate IAR / OAR files. | ||
42 | restart | 48 | restart |
43 | restart Welcome | 49 | restart Welcome |
44 | restart Welcome.ini | 50 | restart Welcome.ini |
@@ -162,7 +168,8 @@ typedef enum | |||
162 | STATUS = 4, | 168 | STATUS = 4, |
163 | BUILD = 5, | 169 | BUILD = 5, |
164 | TEST = 6, | 170 | TEST = 6, |
165 | UPDATE = 7, | 171 | UNGITAR = 7, |
172 | UPDATE = 8, | ||
166 | STOP = 9 | 173 | STOP = 9 |
167 | } modes; | 174 | } modes; |
168 | 175 | ||
@@ -177,8 +184,9 @@ char *modeStrings[] = | |||
177 | "status", | 184 | "status", |
178 | "build", | 185 | "build", |
179 | "test", | 186 | "test", |
187 | "ungitAR", | ||
180 | "update", | 188 | "update", |
181 | "dontDoThis" | 189 | // "dontDoThis" |
182 | "stop" | 190 | "stop" |
183 | }; | 191 | }; |
184 | 192 | ||
@@ -2448,6 +2456,137 @@ gitARend: | |||
2448 | free(name); | 2456 | free(name); |
2449 | } | 2457 | } |
2450 | 2458 | ||
2459 | void ungitar(simData *simd, char *sim, int count, int window, int panes, int pane, int m, int member, char *last) | ||
2460 | { | ||
2461 | /* Extact all the I/OAR files from a gitAR file. | ||
2462 | |||
2463 | Gotta do it the hard way, OpenSim expects the "control file" to be first file in the archive. I guess that's archive.xml, which would normally end up last. | ||
2464 | |||
2465 | Gonna see errors like - | ||
2466 | [FORMS]: Error sending request to http://127.0.0.1:9135/estate: Error: ConnectFailure (Connection refused). Request: METHOD=update_covenant&CovenantID=00000000-0000-0000-0000-000000000000&EstateID=102 | ||
2467 | Real OARs do that to, so not my fault. | ||
2468 | |||
2469 | Results in slightly larger I/OARs, as we store the directory names separately. Can't see any options to not do that. | ||
2470 | Also, we name them .oar.tgz, to NOT hide the fact they are simple tarballs, while still tagging them as I/OARs. | ||
2471 | */ | ||
2472 | char *name = xstrdup(sim); | ||
2473 | |||
2474 | if (FLAG(m)) | ||
2475 | { | ||
2476 | if (member) | ||
2477 | { | ||
2478 | free(name); | ||
2479 | name = xmprintf("%s_%s", sim, last); | ||
2480 | } | ||
2481 | else | ||
2482 | { | ||
2483 | free(name); | ||
2484 | return; | ||
2485 | } | ||
2486 | } | ||
2487 | |||
2488 | char type = FLAG(m) ? 'I' : 'O'; | ||
2489 | char *dir = xmprintf("%s/temp_%c_%s", scBackup, type, name); | ||
2490 | char bar[] = {'_', '-'}; | ||
2491 | int b; | ||
2492 | for (b = 0; b < 2; b++) | ||
2493 | { | ||
2494 | char *gar = xmprintf("%s%cgit%cAR", name, bar[b], type), *gtr = xmprintf("%s/%s.tar.xz", scBackup, gar); | ||
2495 | |||
2496 | if (qfile_exist(dir)) | ||
2497 | { | ||
2498 | E("Cleaning up the mess!"); | ||
2499 | if (shellMeFail("mv %s/*.%car %s", dir, tolower(type), scBackup )) E("Failed cleaning up the mess!"); | ||
2500 | } | ||
2501 | |||
2502 | // Either unpack the old gitAR, or bail. | ||
2503 | qfile_mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP, true); | ||
2504 | if (qfile_exist(gtr)) | ||
2505 | { | ||
2506 | I("Unpacking %s", gtr); | ||
2507 | if (shellMeFail("cd %s; ionice -c3 nice -n 19 tar -xf %s", dir, gtr)) E("Failed to unpack %s!", gtr); | ||
2508 | if ('-' == bar[b]) | ||
2509 | { | ||
2510 | char *t = xmprintf("%s/%s_git%cAR", dir, name, type); | ||
2511 | // Changed from _ to -, but deal with old archives. | ||
2512 | if (qfile_exist(t)) | ||
2513 | { | ||
2514 | V("Moving %s -> %s/%s", t, dir, gar); | ||
2515 | if (shellMeFail("mv %s %s/%s", t, dir, gar)) E("Failed to move %s!", t); | ||
2516 | } | ||
2517 | free(t); | ||
2518 | } | ||
2519 | } | ||
2520 | else | ||
2521 | { | ||
2522 | E("No such gitAR file - %s", gtr); | ||
2523 | goto ungitARend; | ||
2524 | } | ||
2525 | |||
2526 | // Loop backwards through the commits, saving them as ordinary OAR files. | ||
2527 | // The backup script should put only the file name in the commit message. | ||
2528 | char *cmd = xmprintf("cd %s/%s; git shortlog | tail -n 2 | head -n 1 | cut -c 7- ", dir, gar); | ||
2529 | char *prev = xmprintf(""); | ||
2530 | |||
2531 | while (true) | ||
2532 | { | ||
2533 | char *out = qsyscmd(cmd); | ||
2534 | |||
2535 | if (NULL != out) | ||
2536 | { | ||
2537 | out[strlen(out) - 1] = '\0'; | ||
2538 | if ('\0' == out[0]) | ||
2539 | { | ||
2540 | E("Command returned nothing - %s", cmd); | ||
2541 | free(out); | ||
2542 | break; | ||
2543 | } | ||
2544 | D("gitAR archive - |%s|", out); | ||
2545 | if ((strcmp("Initial commit", out) == 0) || (strcmp(prev, out) == 0)) | ||
2546 | { | ||
2547 | D("No more commits."); | ||
2548 | free(out); | ||
2549 | break; | ||
2550 | } | ||
2551 | free(prev); | ||
2552 | prev = xmprintf("%s/%s.tgz", scBackup, out); | ||
2553 | if (!qfile_exist(prev)) | ||
2554 | { | ||
2555 | I("Extracting %s", prev); | ||
2556 | free(prev); | ||
2557 | prev = xmprintf("%s/%s", dir, out); | ||
2558 | // OpenSim insists on the archive.xml file being the very first in the tarball. | ||
2559 | if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 tar -c archive.xml -f %s", dir, gar, prev)) E("Failed to tar %s!", prev); | ||
2560 | if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 tar -r -f %s --exclude='.git*' --exclude='archive.xml' * ", | ||
2561 | dir, gar, prev)) E("Failed to tar %s!", prev); | ||
2562 | // Using gzip instead of something that compresses better, coz OpenSim only knows how to deal with gzipped files. | ||
2563 | if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 gzip -S .tgz %s", dir, gar, prev)) E("Failed to gzip %s!", prev); | ||
2564 | if (shellMeFail("cd %s/%s; mv %s.tgz ../..", dir, gar, prev)) E("Failed to rename %s!", prev); | ||
2565 | } | ||
2566 | else | ||
2567 | W("NOT extracting %s, it already exists.", prev); | ||
2568 | free(prev); | ||
2569 | prev = out; | ||
2570 | if (shellMeFail("cd %s/%s; git reset --hard HEAD~1 2>/dev/null >/dev/null", dir, gar)) E("Failed to git head %s/%s!", dir, gar); | ||
2571 | } | ||
2572 | else | ||
2573 | { | ||
2574 | E("Command failed - %s", cmd); | ||
2575 | break; | ||
2576 | } | ||
2577 | } | ||
2578 | |||
2579 | ungitARend: | ||
2580 | if (shellMeFail("rm -fr %s", dir)) E("Failed to rm!"); | ||
2581 | free(prev); | ||
2582 | free(gtr); | ||
2583 | free(gar); | ||
2584 | } | ||
2585 | free(dir); | ||
2586 | free(name); | ||
2587 | } | ||
2588 | |||
2589 | |||
2451 | // Forward declare this. | 2590 | // Forward declare this. |
2452 | my_ulonglong dbCount(char *table, char *where); | 2591 | my_ulonglong dbCount(char *table, char *where); |
2453 | void doSimsThing(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) | 2592 | void doSimsThing(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) |
@@ -2587,6 +2726,9 @@ byTab has the short name as the key, simData as the value. | |||
2587 | break; | 2726 | break; |
2588 | } | 2727 | } |
2589 | 2728 | ||
2729 | case UNGITAR : // "ungitAR -m avatar name" "ungitAR sim name" | ||
2730 | { | ||
2731 | ungitar(simd, sim, count, window, panes, pane, FLAG(m), member, last); | ||
2590 | break; | 2732 | break; |
2591 | } | 2733 | } |
2592 | 2734 | ||
@@ -8338,6 +8480,8 @@ void sledjchisl_main(void) | |||
8338 | currentMode = BUILD; | 8480 | currentMode = BUILD; |
8339 | else if (strcmp(toys.optargs[0], "test") == 0) | 8481 | else if (strcmp(toys.optargs[0], "test") == 0) |
8340 | currentMode = TEST; | 8482 | currentMode = TEST; |
8483 | else if (strcmp(toys.optargs[0], "ungitar") == 0) | ||
8484 | currentMode = UNGITAR; | ||
8341 | else if (strcmp(toys.optargs[0], "update") == 0) | 8485 | else if (strcmp(toys.optargs[0], "update") == 0) |
8342 | currentMode = UPDATE; | 8486 | currentMode = UPDATE; |
8343 | else if (strcmp(toys.optargs[0], "stop") == 0) | 8487 | else if (strcmp(toys.optargs[0], "stop") == 0) |