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.
53 lines
2.0 KiB
C
53 lines
2.0 KiB
C
// fontdpi_gtk3.h: the font DPI guard for GTK 3 builds, in C so that the
|
|
// native probe in testdata compiles the same code the app runs.
|
|
#include <gtk/gtk.h>
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
|
|
// magpie_font_dpi gives GDK a font resolution when it has none. GDK says
|
|
// -1 for an unset one, and WebKitGTK 2.54.1's GTK 3 settings reader
|
|
// (SystemSettingsManagerProxy::xftDPI) multiplies it by 1024 without a
|
|
// check: its pages then lay out with a viewport of -91008px and a body
|
|
// font of 9000000px (#1371). A positive resolution is left as it is. An
|
|
// unset one takes the GTK setting gtk-xft-dpi, or 96, times a valid
|
|
// GDK_DPI_SCALE, as GTK itself does with a positive gtk-xft-dpi.
|
|
// Returns -1 when GTK has no display, 0 when the resolution was kept,
|
|
// 1 when it was set.
|
|
static int magpie_font_dpi(void) {
|
|
if (!gtk_init_check(NULL, NULL))
|
|
return -1;
|
|
GdkScreen *screen = gdk_screen_get_default();
|
|
if (screen == NULL)
|
|
return -1;
|
|
double dpi = gdk_screen_get_resolution(screen);
|
|
if (isfinite(dpi) && dpi > 0)
|
|
return 0;
|
|
gint xft = -1;
|
|
g_object_get(gtk_settings_get_default(), "gtk-xft-dpi", &xft, NULL);
|
|
dpi = xft > 0 ? xft / 1024.0 : 96.0;
|
|
const char *env = g_getenv("GDK_DPI_SCALE");
|
|
if (env != NULL) {
|
|
char *end;
|
|
double scale = g_ascii_strtod(env, &end);
|
|
if (end != env && *end == '\0' && isfinite(scale) && scale > 0 && isfinite(dpi * scale))
|
|
dpi *= scale;
|
|
}
|
|
gdk_screen_set_resolution(screen, dpi);
|
|
return 1;
|
|
}
|
|
|
|
static gboolean magpie_font_dpi_idle(gpointer data) {
|
|
if (magpie_font_dpi() == 1)
|
|
g_message("magpie: GTK has no font DPI set; using %g (#1371)",
|
|
gdk_screen_get_resolution(gdk_screen_get_default()));
|
|
return G_SOURCE_REMOVE;
|
|
}
|
|
|
|
// magpie_font_dpi_first runs magpie_font_dpi as the GTK main loop starts.
|
|
// GtkApplication has initialised GTK by then, with the program name Wails
|
|
// set, and Wails makes each window from an idle callback of default idle
|
|
// priority; one of G_PRIORITY_HIGH runs before all of them.
|
|
static void magpie_font_dpi_first(void) {
|
|
g_idle_add_full(G_PRIORITY_HIGH, magpie_font_dpi_idle, NULL, NULL);
|
|
}
|