Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Auto-backup: a day whose first two names belong to other installs still gets its copy
Duarte Santos76b5c5659e66
diff --git a/frontend/src/lib/mobile.autobackup.test.js b/frontend/src/lib/mobile.autobackup.test.jsindex 600efab44..2ce1f21f3 100644--- a/frontend/src/lib/mobile.autobackup.test.js+++ b/frontend/src/lib/mobile.autobackup.test.js@@ -123,6 +123,12 @@ describe('writeAutoBackup where today\'s name belongs to another install', () =>expect(JSON.parse(h.files.get('DOCUMENTS/' + other))).toEqual({ theirs: true })})+ it('with the first two names owned by earlier installs, the copy goes under the third', async () => {+ for (const n of ['', '-2']) { const p = 'openGym/' + backup(todayISO()).replace('.json', n + '.json'); put(p, '{"theirs":true}'); h.foreign.add(p) }+ await writeAutoBackup({ n: 3 })+ expect(JSON.parse(h.files.get('DOCUMENTS/openGym/' + backup(todayISO()).replace('.json', '-3.json')))).toEqual({ n: 3 })+ })+it('counts the second names among the fourteen it keeps, and prunes them like any other', async () => {for (let i = 0; i < 20; i++) put('openGym/' + backup(day(i)).replace('.json', i % 2 ? '-2.json' : '.json'))await writeAutoBackup({})diff --git a/frontend/src/lib/mobile.js b/frontend/src/lib/mobile.jsindex 0dd7abba5..6aa9adf5a 100644--- a/frontend/src/lib/mobile.js+++ b/frontend/src/lib/mobile.js@@ -270,12 +270,12 @@ export const AUTO_BACKUP_DIR = 'openGym'export const AUTO_BACKUP_KEEP = 14// Only the exact names writeAutoBackup gives its files are ever pruned; anything else someone// keeps in the folder is theirs.-const AUTO_BACKUP_NAME = /^opengym-backup-\d{4}-\d{2}-\d{2}(-2)?\.json$/+const AUTO_BACKUP_NAME = /^opengym-backup-\d{4}-\d{2}-\d{2}(-[2-9])?\.json$/// Android's scoped storage lets an install write over, list and delete only the files it wrote// itself. After a reinstall, or with the test build beside the real one, today's name can belong// to the other install: writing it fails with EACCES, and that day went without a copy, silently.-// The copy then goes under the day's second name, which this install owns after its first write.+// The copy then goes under the day's next name (-2 up to -9), which this install owns after its first write.// The other install's files stay where they are; this one cannot see them to prune them.export async function writeAutoBackup(state) {const day = todayISO()@@ -293,11 +293,14 @@ export async function writeAutoBackup(state) {encoding: fs.Encoding.UTF8,recursive: true,})- let name = `opengym-backup-${day}.json`- try { await write(name) } catch (e) {- name = `opengym-backup-${day}-2.json`- try { await write(name) } catch (e2) { return } // best effort — the private mirror in Directory.Data still has the data+ // The day's names in turn: a second earlier install (or a third) can own the first two, and that+ // day then went without a copy, silently, while the newest file there was another install's.+ let name = null+ for (const suffix of ['', '-2', '-3', '-4', '-5', '-6', '-7', '-8', '-9']) {+ const n = `opengym-backup-${day}${suffix}.json`+ try { await write(n); name = n; break } catch (e) { /* owned by another install, or the disk said no: the next name */ }}+ if (!name) return // best effort — the private mirror in Directory.Data still has the data// Pruning waits for a successful write: a full disk must never cost the copies already there.await pruneAutoBackups(fs, name)}