diff options
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 133 |
1 files changed, 70 insertions, 63 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 175cf4d..e076654 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c | |||
@@ -701,6 +701,19 @@ int shellMe(char *format, ...) | |||
701 | } | 701 | } |
702 | 702 | ||
703 | 703 | ||
704 | int hasContents(char *file) | ||
705 | { | ||
706 | struct stat st; | ||
707 | |||
708 | if (0 == lstat(file, &st)) | ||
709 | { | ||
710 | if (0 != st.st_size) | ||
711 | return TRUE; | ||
712 | } | ||
713 | return FALSE; | ||
714 | } | ||
715 | |||
716 | |||
704 | static void addStrL(qlist_t *list, char *s) | 717 | static void addStrL(qlist_t *list, char *s) |
705 | { | 718 | { |
706 | list->addlast(list, s, strlen(s) + 1); | 719 | list->addlast(list, s, strlen(s) + 1); |
@@ -2053,7 +2066,10 @@ byTab has the short name as the key, simData as the value. | |||
2053 | if (NULL != ourSims->backup) | 2066 | if (NULL != ourSims->backup) |
2054 | { | 2067 | { |
2055 | if ('\0' == rSync[0]) | 2068 | if ('\0' == rSync[0]) |
2069 | { | ||
2070 | I("Running gitar on %s %s", sim, last); | ||
2056 | shellMeFail("%s/current/bin/sledjchisl gitar -m %s %s %s", scRoot, FLAG(v) ? "-v" : "", sim, last); | 2071 | shellMeFail("%s/current/bin/sledjchisl gitar -m %s %s %s", scRoot, FLAG(v) ? "-v" : "", sim, last); |
2072 | } | ||
2057 | sendTmuxCmd(ourSims->backup, toybuf); | 2073 | sendTmuxCmd(ourSims->backup, toybuf); |
2058 | // if (0 == do) | 2074 | // if (0 == do) |
2059 | { | 2075 | { |
@@ -2083,7 +2099,10 @@ byTab has the short name as the key, simData as the value. | |||
2083 | // keep in mind some old files had munged names like "Tiffanie_s_Paradise-2021-06-23_05:11:38.oar" | 2099 | // keep in mind some old files had munged names like "Tiffanie_s_Paradise-2021-06-23_05:11:38.oar" |
2084 | I("Sim %s is being backed up to %s/backups/%s-%s.oar.", simd->name, scRoot, simd->tab, date); | 2100 | I("Sim %s is being backed up to %s/backups/%s-%s.oar.", simd->name, scRoot, simd->tab, date); |
2085 | if ('\0' == rSync[0]) | 2101 | if ('\0' == rSync[0]) |
2102 | { | ||
2103 | I("Running gitar on %s", simd->tab); | ||
2086 | shellMeFail("%s/current/bin/sledjchisl gitar %s %s", scRoot, FLAG(v) ? "-v" : "", simd->tab); | 2104 | shellMeFail("%s/current/bin/sledjchisl gitar %s %s", scRoot, FLAG(v) ? "-v" : "", simd->tab); |
2105 | } | ||
2087 | snprintf(toybuf, sizeof(toybuf), "save oar --all %s/%s-%s.oar", scBackup, simd->tab, date); | 2106 | snprintf(toybuf, sizeof(toybuf), "save oar --all %s/%s-%s.oar", scBackup, simd->tab, date); |
2088 | sendTmuxCmd(simd->paneID, toybuf); | 2107 | sendTmuxCmd(simd->paneID, toybuf); |
2089 | // if (0 == do) | 2108 | // if (0 == do) |
@@ -2133,15 +2152,12 @@ byTab has the short name as the key, simData as the value. | |||
2133 | } | 2152 | } |
2134 | 2153 | ||
2135 | char type = FLAG(m) ? 'I' : 'O'; | 2154 | char type = FLAG(m) ? 'I' : 'O'; |
2136 | char *gar = xmprintf("%s_git%cAR", name, type); | 2155 | char *gar = xmprintf("%s-git%cAR", name, type), *gtr = xmprintf("%s/%s.tar.xz", scBackup, gar); |
2137 | char *gtr = xmprintf("%s/%s-git%cAR.tar.xz", scBackup, name, type); | 2156 | char *dir = xmprintf("%s/temp_%c_%s", scBackup, type, name); |
2138 | char *dir = xmprintf("%s/temp_backups%c_%s", scBackup, type, name); | 2157 | char *glog = xmprintf("%s/log.log", scBackup), *gerr = xmprintf("%s/errors", dir); |
2139 | // Make sure stuff that's already compressed doesn't get compressed by git. | 2158 | // Make sure stuff that's already compressed doesn't get compressed by git. |
2140 | // Also tries to protect binaries from mangling. | 2159 | // Also tries to protect binaries from mangling. |
2141 | char *gab = xmprintf("%s/%s/.gitattributes", dir, gar); | 2160 | char *gab = xmprintf("%s/%s/.gitattributes", dir, gar), *gad = |
2142 | char *ga = xmprintf("%s/%s", dir, gar); | ||
2143 | char *gal = xmprintf("%s/log", scBackup); | ||
2144 | char *gad = | ||
2145 | "*.bvh -delta -diff -text\n" | 2161 | "*.bvh -delta -diff -text\n" |
2146 | "*.jp2 -delta -diff -text\n" | 2162 | "*.jp2 -delta -diff -text\n" |
2147 | "*.jpg -delta -diff -text\n" | 2163 | "*.jpg -delta -diff -text\n" |
@@ -2154,10 +2170,8 @@ byTab has the short name as the key, simData as the value. | |||
2154 | 2170 | ||
2155 | if (qfile_exist(dir)) | 2171 | if (qfile_exist(dir)) |
2156 | { | 2172 | { |
2157 | if (shellMeFail("echo 'Mess left over from last backup in %d, not gonna run!' >>%s/errors", dir)) | 2173 | if (shellMeFail("echo 'Mess left over from last backup in %d, not gonna run!' >>%s", dir, gerr)) E("Cleaning up the mess!"); |
2158 | E("Failed cleaning up the mess!"); | 2174 | if (shellMeFail("mv %s/*.%car %s 2>&1 >>%s", dir, tolower(type), scBackup, gerr)) E("Failed cleaning up the mess!"); |
2159 | if (shellMeFail("mv %s/*.%car %s 2>&1 >/dev/null", dir, tolower(type), scBackup)) | ||
2160 | E("Failed cleaning up the mess!"); | ||
2161 | goto gitARend; | 2175 | goto gitARend; |
2162 | } | 2176 | } |
2163 | 2177 | ||
@@ -2166,34 +2180,38 @@ byTab has the short name as the key, simData as the value. | |||
2166 | if (qfile_exist(gtr)) | 2180 | if (qfile_exist(gtr)) |
2167 | { | 2181 | { |
2168 | I("Unpacking %s", gtr); | 2182 | I("Unpacking %s", gtr); |
2169 | if (shellMeFail("cd %s; ionice -c3 nice -n 19 tar -xf %s", dir, gtr)) | 2183 | if (shellMeFail("cd %s; ionice -c3 nice -n 19 tar -xf %s >>%s", dir, gtr, gerr)) E("Failed to unpack %s!", gtr); |
2170 | E("Failed to unpack %s!", gtr); | 2184 | char *t = xmprintf("%s/%s_git%cAR", dir, name, type); |
2185 | // Changed from _ to -, but deal with old archives. | ||
2186 | if (qfile_exist(t)) | ||
2187 | { | ||
2188 | if (shellMeFail("mv %s %s/%s", t, dir, gar)) E("Failed to move %s!", t); | ||
2189 | } | ||
2190 | free(t); | ||
2171 | } | 2191 | } |
2172 | else | 2192 | else |
2173 | { | 2193 | { |
2174 | qfile_mkdir(gar, S_IRWXU | S_IRGRP | S_IXGRP, true); | 2194 | qfile_mkdir(gar, S_IRWXU | S_IRGRP | S_IXGRP, true); |
2175 | // git will create gar for us. | 2195 | // git will create gar for us. |
2176 | if (shellMeFail("cd %s; git init %s >%s", dir, gar, gal)) | 2196 | if (shellMeFail("cd %s; git init --quiet %s >>%s", dir, gar, gerr)) E("Failed to git init %s/%s!", dir, gar); |
2177 | E("Failed to git init %s/%s!", dir, gar); | ||
2178 | 2197 | ||
2179 | // Coz git insists. | 2198 | // Coz git insists. |
2180 | if (shellMeFail("cd %s/%s; git config user.email \"opensim@$(hostname -A | cut -d ' ' -f 1)\"", dir, gar)) | 2199 | if (shellMeFail("cd %s/%s; git config user.email \"opensim@$(hostname -A | cut -d ' ' -f 1)\"", dir, gar)) E("Failed to git config user.email!"); |
2181 | E("Failed to git config user.email!"); | 2200 | if (shellMeFail("cd %s/%s; git config user.name \"opensim\"", dir, gar)) E("Failed to git config user.name!"); |
2182 | if (shellMeFail("cd %s/%s; git config user.name \"opensim\"", dir, gar)) | ||
2183 | E("Failed to git config user.name!"); | ||
2184 | 2201 | ||
2185 | // Coz git insists on having something comitted before it can change the branch name. | 2202 | // Coz git insists on having something comitted before it can change the branch name. |
2186 | if (-1 == qfile_save(gab, gad, strlen(gad), false)) | 2203 | if (-1 == qfile_save(gab, gad, strlen(gad), false)) E("Faild to write %s file!", gad); |
2187 | E("Faild to write %s file!", ga); | 2204 | if (shellMeFail("cd %s/%s; git add .gitattributes >>%s", dir, gar, gerr)) E("Failed to git add!"); |
2188 | if (shellMeFail("cd %s/%s; git add .gitattributes >>%s", dir, gar, gal)) | ||
2189 | E("Failed to git add!"); | ||
2190 | V("Committing initial git."); | 2205 | V("Committing initial git."); |
2191 | if (shellMeFail("cd %s/%s; git commit -qm \"Initial commit\" >>%s || echo \"ERROR - Could not commit!\" >>%s/errors ", | 2206 | if (shellMeFail("cd %s/%s; git commit -qm \"Initial commit\" >>%s || echo \"ERROR - Could not commit!\" >>%s", |
2192 | dir, gar, gal, dir)) | 2207 | dir, gar, glog, gerr)) E("Failed to git commit!"); |
2193 | E("Failed to git commit!"); | 2208 | if (shellMeFail("cd %s/%s; git branch -m master Domme >>%s", dir, gar, gerr)) E("Failed to git branch -m master Domme!"); |
2194 | if (shellMeFail("cd %s/%s; git branch -m master Domme >>%s", dir, gar, gal)) | ||
2195 | E("Failed to git branch -m master Domme!"); | ||
2196 | } | 2209 | } |
2210 | // Doing these each time, to catch those old ones that didn't have them. | ||
2211 | // Coz otherwise git commit starts a gc run IN THE BACKGROUD, which screws up trying to tarball it. | ||
2212 | if (shellMeFail("cd %s/%s; git config gc.autodetach false", dir, gar)) E("Failed to git config gc.autodetach!"); | ||
2213 | // Don't want it running in the foreground either, coz it dumps on the console, we do a gc --quiet later anyway. | ||
2214 | if (shellMeFail("cd %s/%s; git config gc.auto 0", dir, gar)) E("Failed to git config gc.auto!"); | ||
2197 | 2215 | ||
2198 | // Git is such a pedantic bitch, let's just fucking ignore any errors it gives due to lack of anything to do. | 2216 | // Git is such a pedantic bitch, let's just fucking ignore any errors it gives due to lack of anything to do. |
2199 | // Even worse the OpenSim devs breaking logout tracking gives git plenty of nothing to do. lol | 2217 | // Even worse the OpenSim devs breaking logout tracking gives git plenty of nothing to do. lol |
@@ -2207,29 +2225,21 @@ byTab has the short name as the key, simData as the value. | |||
2207 | new->extra = (long) ourARs; | 2225 | new->extra = (long) ourARs; |
2208 | dirtree_handle_callback(new, filterARs); | 2226 | dirtree_handle_callback(new, filterARs); |
2209 | qsort(ourARs->ARs, ourARs->num, sizeof(char *), qstrcmp); | 2227 | qsort(ourARs->ARs, ourARs->num, sizeof(char *), qstrcmp); |
2210 | free(ga); | ||
2211 | ga = xmprintf("%s/errors", dir); | ||
2212 | for (i = 0; i < ourARs->num; i++) | 2228 | for (i = 0; i < ourARs->num; i++) |
2213 | { | 2229 | { |
2214 | I("Adding %s to %s", ourARs->ARs[i], gtr); | 2230 | I("Adding %s to %s", ourARs->ARs[i], gtr); |
2215 | // Deal with deletions in the inventory / sim, easy method, which becomes a nop for files that stay in the git add below. | 2231 | // Deal with deletions in the inventory / sim, easy method, which becomes a nop for files that stay in the git add below. |
2216 | if (shellMeFail("cd %s/%s; rm -fr * >>%s", dir, gar, gal)) | 2232 | if (shellMeFail("cd %s/%s; rm -fr * >>%s", dir, gar, gerr)) E("Failed to rm!"); |
2217 | E("Failed to rm!"); | ||
2218 | if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 tar -xzf \"%s/%s\" || echo \"ERROR - Could not unpack %s !\" >>%s", | 2233 | if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 tar -xzf \"%s/%s\" || echo \"ERROR - Could not unpack %s !\" >>%s", |
2219 | dir, gar, scBackup, ourARs->ARs[i], ourARs->ARs[i], ga)) | 2234 | dir, gar, scBackup, ourARs->ARs[i], ourARs->ARs[i], gerr)) E("Failed to unpack %s!", ourARs->ARs[i]); |
2220 | E("Failed to unpack %s!", ourARs->ARs[i]); | 2235 | if (!hasContents(gerr)) |
2221 | if (!qfile_exist(ga)) | ||
2222 | { | 2236 | { |
2223 | if (shellMeFail("cd %s/%s; git add * >>%s", dir, gar, gal)) | 2237 | if (shellMeFail("cd %s/%s; git add * >>%s", dir, gar, glog)) E("Failed to git add!"); |
2224 | E("Failed to git add!"); | ||
2225 | // The \\* bit is to escape the \ from snprintf, which itself escapes the * from the shell. | 2238 | // The \\* bit is to escape the \ from snprintf, which itself escapes the * from the shell. |
2226 | if (shellMeFail("cd %s/%s; git add */\\* >>%s", dir, gar, gal)) | 2239 | if (shellMeFail("cd %s/%s; git add */\\* >>%s", dir, gar, gerr)) E("Failed to git add!"); |
2227 | E("Failed to git add!"); | ||
2228 | // Gotta add this again, coz of the rm. Apparently rm removes dotfiles, but add doesn't! | 2240 | // Gotta add this again, coz of the rm. Apparently rm removes dotfiles, but add doesn't! |
2229 | if (-1 == qfile_save(gab, gad, strlen(gad), false)) | 2241 | if (-1 == qfile_save(gab, gad, strlen(gad), false)) E("Faild to write %s file!", gab); |
2230 | E("Faild to write %s file!", ga); | 2242 | if (shellMeFail("cd %s/%s; git add .gitattributes >>%s", dir, gar, gerr)) E("Failed to git add!"); |
2231 | if (shellMeFail("cd %s/%s; git add .gitattributes >>%s", dir, gar, gal)) | ||
2232 | E("Failed to git add!"); | ||
2233 | 2243 | ||
2234 | // Magic needed to figure out if there's anything to commit. | 2244 | // Magic needed to figure out if there's anything to commit. |
2235 | // After all the pain to get this to work, there's an ever changing timestamp in archive.xml that screws it up. | 2245 | // After all the pain to get this to work, there's an ever changing timestamp in archive.xml that screws it up. |
@@ -2237,18 +2247,15 @@ byTab has the short name as the key, simData as the value. | |||
2237 | // TODO - I could sed out that timestamp, and put it back again based on the OAR file name when extracting. | 2247 | // TODO - I could sed out that timestamp, and put it back again based on the OAR file name when extracting. |
2238 | // IARs don't seem to have the timestamp. | 2248 | // IARs don't seem to have the timestamp. |
2239 | int j = shellMe("cd %s/%s; t=$(git status --porcelain) && [ -z \"${t}\" ]", dir, gar); | 2249 | int j = shellMe("cd %s/%s; t=$(git status --porcelain) && [ -z \"${t}\" ]", dir, gar); |
2240 | if (!WIFEXITED(j)) | 2250 | if (!WIFEXITED(j)) E("git status failed!"); |
2241 | E("git status failed!"); | ||
2242 | else if (1 == WEXITSTATUS(j)) | 2251 | else if (1 == WEXITSTATUS(j)) |
2243 | { | 2252 | { |
2244 | V("Committing changes from %s", ourARs->ARs[i]); | 2253 | V("Committing changes from %s", ourARs->ARs[i]); |
2245 | // Note this commit message has to be just the file name, as the ungitAR script uses it. | 2254 | // Note this commit message has to be just the file name, as the ungitAR script uses it. |
2246 | if (shellMeFail("cd %s/%s; git commit -a -qm \"%s\" >>%s || echo \"ERROR - Could not commit %s !\" >>%s ", | 2255 | if (shellMeFail("cd %s/%s; git commit -a -qm \"%s\" >>%s || echo \"ERROR - Could not commit %s !\" >>%s ", |
2247 | dir, gar, ourARs->ARs[i], ourARs->ARs[i], gal, ga)) | 2256 | dir, gar, ourARs->ARs[i], ourARs->ARs[i], glog, gerr)) E("Failed to git commit!"); |
2248 | E("Failed to git commit!"); | 2257 | if (hasContents(gerr)) |
2249 | if (qfile_exist(ga)) | ||
2250 | { | 2258 | { |
2251 | free(ga); | ||
2252 | free(ourARs->ARs[i]); | 2259 | free(ourARs->ARs[i]); |
2253 | goto gitARend; | 2260 | goto gitARend; |
2254 | } | 2261 | } |
@@ -2256,36 +2263,36 @@ byTab has the short name as the key, simData as the value. | |||
2256 | else | 2263 | else |
2257 | V("No changes to commit from %s.", ourARs->ARs[i]); | 2264 | V("No changes to commit from %s.", ourARs->ARs[i]); |
2258 | } | 2265 | } |
2259 | if (!qfile_exist(ga)) | 2266 | if (!hasContents(gerr)) |
2260 | { | 2267 | { |
2261 | if (shellMeFail("mv %s/%s %s", scBackup, ourARs->ARs[i], dir)) | 2268 | if (shellMeFail("mv %s/%s %s", scBackup, ourARs->ARs[i], dir)) E("Failed to move %s!", ourARs->ARs[i]); |
2262 | E("Failed to move %s!", ourARs->ARs[i]); | ||
2263 | } | 2269 | } |
2264 | free(ourARs->ARs[i]); | 2270 | free(ourARs->ARs[i]); |
2265 | } | 2271 | } |
2266 | 2272 | ||
2267 | if (!qfile_exist(ga)) | 2273 | if (!hasContents(gerr)) |
2268 | { | 2274 | { |
2269 | I("Compressing gitAR %s", gtr); | 2275 | I("Checking git repo %s", gtr); |
2276 | if (shellMeFail("cd %s/%s; git fsck --strict --lost-found --no-progress >>%s || echo \"ERROR - Problem with git fsck %s !\" >>%s ", | ||
2277 | dir, gar, glog, gtr, gerr)) E("Failed to git fsck!"); | ||
2278 | if (shellMeFail("cd %s/%s; git gc --aggressive --prune=all --quiet >>%s || echo \"ERROR - Problem with git gc %s !\" >>%s ", | ||
2279 | dir, gar, glog, gtr, gerr)) E("Failed to git gc!"); | ||
2280 | I("Compressing %s", gtr); | ||
2270 | if (shellMeFail("cd %s; XZ_OPT='-9e' ionice -c3 nice -n 19 tar -c --xz %s -f %s || echo 'ERROR - Could not pack gitAR!' >>%s", | 2281 | if (shellMeFail("cd %s; XZ_OPT='-9e' ionice -c3 nice -n 19 tar -c --xz %s -f %s || echo 'ERROR - Could not pack gitAR!' >>%s", |
2271 | dir, gar, gtr, ga)) | 2282 | dir, gar, gtr, gerr)) E("Failed to git add!"); |
2272 | E("Failed to git add!"); | ||
2273 | } | 2283 | } |
2274 | gitARend: | 2284 | gitARend: |
2275 | free(ga); | 2285 | if (hasContents(gerr)) E("Failed to process the archives, look in %s for errors!", gerr); |
2276 | ga = xmprintf("%s/errors", dir); | ||
2277 | if (qfile_exist(ga)) | ||
2278 | E("Failed to process the archives, look in %s for errors!", ga); | ||
2279 | else | 2286 | else |
2280 | { | 2287 | { |
2281 | if (shellMeFail("rm -fr %s", dir)) | 2288 | if (shellMeFail("rm -fr %s", dir)) E("Failed to rm!"); |
2282 | E("Failed to rm!"); | ||
2283 | } | 2289 | } |
2284 | free(ga); | ||
2285 | free(ourARs->ARs); | 2290 | free(ourARs->ARs); |
2286 | free(ourARs->this); | 2291 | free(ourARs->this); |
2287 | free(ourARs); | 2292 | free(ourARs); |
2288 | free(gab); | 2293 | free(gab); |
2294 | free(gerr); | ||
2295 | free(glog); | ||
2289 | free(dir); | 2296 | free(dir); |
2290 | free(gtr); | 2297 | free(gtr); |
2291 | free(gar); | 2298 | free(gar); |