JasonLeeForOnly's WebDAV sync failed with only "not a magpie backup" for
several versions, and nothing on the page got past it. A WebDAV GET of the
backup can come back as a body that isn't the file in several ways; each is
now reproduced with an httptest server that answers the way the real one
does:
Unpacked (WebDAV and S3): gzip with or without Content-Encoding (a proxy
that drops the header), x-gzip, zstd with or without the header, deflate
(zlib or raw), and a header that says gzip over a plain body. Bodies are
told by magic number; a backup is JSON, so either magic is never the file.
Brotli (br) can't be unpacked and is said as itself, with what to turn off.
Said, with no upload offered: an HTML page answered with 200 (Nextcloud
login after a redirect, Cloudflare Access, an AList/OpenList web app, an
rclone directory listing, a captive portal), with its <title> and the
host/path a redirect ended at (query, fragment and user dropped), and
where the WebDAV address is for 坚果云 and Nextcloud; an XML answer, by its
root element.
Said, with Upload as the way out: an empty (0-byte) file, a backup cut
short or damaged (the automatic rebuild is unchanged and still goes first
when its rules allow), another app's file ("format": "…"), other JSON,
and any other file by its content type. Messages carry the size, kind and a
page title only, never the file's contents.
backup.Open now tells ErrNotBackup (doesn't begin like a backup) from
ErrCorrupt (begins like one, cut short). The status carries the kind as
serverFile; Settings › Sync and backup says it in the reader's language,
wraps it whole, and shows "Upload this computer's setup" only when the file
may be replaced. davsync.Upload (POST /api/davsync/upload, `magpie webdav
upload`, `magpie s3 upload`) asks first in the GUI, re-reads the file,
refuses a backup this computer opens, one sealed with another passphrase,
a newer magpie's, a page and an XML answer, keeps the server's copy in the
sync folder (0600, newest 5) and writes nothing if that fails, then writes
with If-Match on the version read. New strings in en, zh, zh-TW, ja, de.
Verified: internal/davsync/not_backup_test.go (TestReadCompressedBackup,
TestReadBrotliSaid, TestServerAnswerSaid, TestCutBackupSaidAndUploaded,
TestS3ReadCompressedObject; Upload-only parts stripped to compile) fails
on e4a90aa6 for every compressed case but "gzip said", Brotli, every
server-answer case, the cut case and S3 gzip, and passes here. Dropping
the Replace check in Upload turns the page/XML cases red ("Upload wrote
over a page"). gofmt -l clean; go vet darwin, GOOS=linux and GOOS=windows
-tags nogui on ., davsync, backup, gui; full go test -tags nogui ./... ok;
-race on davsync and backup ok. GUI: sync-not-backup.test.cjs (en, zh,
zh-TW, ja, de; 900 and 440px), sync-*, s3-sync, gui-de, gui-ja, gui-zh-tw,
click-scroll in Chromium and WebKit, 81 pass. Not tried against a real
WebDAV server or on the Windows box; the reporter's server is unknown.
68 lines
2.3 KiB
C
68 lines
2.3 KiB
C
// fontdpi_probe opens a GTK 3 window with a WebKitGTK page and prints what
|
|
// the page measures. argv[1] is the font DPI GDK is left with before the
|
|
// first webview (-1 is GDK's unset value, #1371). Built with
|
|
// -DMAGPIE_FONT_DPI it runs magpie's guard first, as the app does.
|
|
#include <gtk/gtk.h>
|
|
#include <webkit2/webkit2.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#ifdef MAGPIE_FONT_DPI
|
|
#include "fontdpi_gtk3.h"
|
|
#endif
|
|
|
|
static GMainLoop *loop;
|
|
static int status = 1;
|
|
|
|
static void measured(GObject *view, GAsyncResult *res, gpointer data) {
|
|
GError *err = NULL;
|
|
JSCValue *v = webkit_web_view_evaluate_javascript_finish(WEBKIT_WEB_VIEW(view), res, &err);
|
|
if (v == NULL) {
|
|
fprintf(stderr, "js: %s\n", err ? err->message : "no result");
|
|
} else {
|
|
char *s = jsc_value_to_string(v);
|
|
printf("layout dpi=%g allocated=%d %s\n", gdk_screen_get_resolution(gdk_screen_get_default()),
|
|
gtk_widget_get_allocated_width(GTK_WIDGET(view)), s);
|
|
g_free(s);
|
|
g_object_unref(v);
|
|
status = 0;
|
|
}
|
|
g_main_loop_quit(loop);
|
|
}
|
|
|
|
static void loaded(WebKitWebView *view, WebKitLoadEvent ev, gpointer data) {
|
|
if (ev == WEBKIT_LOAD_FINISHED)
|
|
webkit_web_view_evaluate_javascript(view,
|
|
"'viewport=' + innerWidth + ' font=' + parseFloat(getComputedStyle(document.body).fontSize)",
|
|
-1, NULL, NULL, NULL, measured, NULL);
|
|
}
|
|
|
|
static gboolean timeout(gpointer data) {
|
|
fprintf(stderr, "timed out\n");
|
|
g_main_loop_quit(loop);
|
|
return G_SOURCE_REMOVE;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc != 2)
|
|
return 2;
|
|
if (!gtk_init_check(NULL, NULL))
|
|
return 3;
|
|
printf("initial dpi=%g\n", gdk_screen_get_resolution(gdk_screen_get_default()));
|
|
gdk_screen_set_resolution(gdk_screen_get_default(), g_ascii_strtod(argv[1], NULL));
|
|
#ifdef MAGPIE_FONT_DPI
|
|
printf("guard=%d\n", magpie_font_dpi());
|
|
#endif
|
|
loop = g_main_loop_new(NULL, FALSE);
|
|
GtkWidget *w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
gtk_window_set_default_size(GTK_WINDOW(w), 420, 520);
|
|
GtkWidget *view = webkit_web_view_new();
|
|
gtk_container_add(GTK_CONTAINER(w), view);
|
|
g_signal_connect(view, "load-changed", G_CALLBACK(loaded), NULL);
|
|
gtk_widget_show_all(w);
|
|
webkit_web_view_load_html(WEBKIT_WEB_VIEW(view),
|
|
"<!doctype html><meta name=viewport content='width=device-width'><style>body{margin:0;font:16px sans-serif}</style><p>magpie</p>", NULL);
|
|
g_timeout_add_seconds(20, timeout, NULL);
|
|
g_main_loop_run(loop);
|
|
return status;
|
|
}
|