From 8624486fc150f7ebb01543c37c893dc7e64b2f94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Fri, 18 Oct 2024 14:38:31 -0400
Subject: [PATCH] Fix cache subdirectories on Windows.

Windows appears to treat backslashes and slashes the same when
using the API, but Windows always returns backslashes.  Convert
backslashes to slashes in clean_path() to ensure paths compare the
same regardless of them being specified with backslashes or slashes.

There's still an open question of what to do about paths received
from the remote with backslashes in them, but I suspect that doing
that would actually work on *nix systems and break on Windows systems,
so hopefully whoever does that can fogure out what's going on.
---
 src/syncterm/CHANGES |  1 +
 src/syncterm/term.c  | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/src/syncterm/CHANGES b/src/syncterm/CHANGES
index eb6a470d79..9dabb9f666 100644
--- a/src/syncterm/CHANGES
+++ b/src/syncterm/CHANGES
@@ -3,6 +3,7 @@ Version 1.2rc3
 Get Haiku support building again
 Properly quit video subsystem from video thread - fixes Haiku crash
 Create dirs on macOS when needed - fixes adding first BBS
+Fix cache subdirectories on Windows
 
 Version 1.2rc2
 --------------
diff --git a/src/syncterm/term.c b/src/syncterm/term.c
index a01bf82a5b..41d1c1c3bb 100644
--- a/src/syncterm/term.c
+++ b/src/syncterm/term.c
@@ -2426,7 +2426,21 @@ clean_path(char *fn, size_t fnsz)
 {
 	char *fp;
 
+#ifdef _WIN32
+	// Convert all backslashes to slashes...
+	for (char *fpc = fn; *fpc; fpc++) {
+		if (*fpc == '\\')
+			*fpc = '/';
+	}
+#endif
 	fp = _fullpath(NULL, fn, fnsz);
+#ifdef _WIN32
+	// Convert all backslashes to slashes...
+	for (char *fpc = fp; *fpc; fpc++) {
+		if (*fpc == '\\')
+			*fpc = '/';
+	}
+#endif
 	if ((fp == NULL) || strcmp(fp, fn)) {
 		FREE_AND_NULL(fp);
 		return 0;
-- 
GitLab