Skip to content

Commit 0605614

Browse files
committed
fix #3057: route AlreadyExists uploads to /content/maps/ not /content/games/
Re-uploading an existing map dropped the file into /content/games/, so BuildLinks (which probes /content/maps/) never saw it and LinkCount stayed 0 — the "WILL NOT BE DOWNLOADABLE" the ticket describes. Root cause: `res.ResourceInfo is Map` was the subfolder discriminator. On the AlreadyExists path UnitSyncer skips GetResourceFromFileName and returns the plain ResourceInfo from ArchiveCache (ArchiveCache.cs:36 constructs them as `new ResourceInfo() { ... }`, not Map), so the check is silently false. Only the brand-new-registration path produced a Map instance, so only new-map uploads ever worked. Verified empirically against live zero-k.info — all 5 maps from the ticket are sitting at /content/games/{name}.sd7 (200 OK) instead of /content/maps/. Other casualties found via the same scan: Hide_and_Seek_2.2.3, Coastlines_Dry_V2.2, Supreme_Crossing_V1. Fix: derive `isMap` from `resource.TypeID == ResourceType.Map` (DB is the source of truth; we're already loading `resource` in this scope). Keep `is Map` as the fallback for the very first registration of a new map where the DB row doesn't exist yet at the point of subfolder choice. Stranded files at /content/games/ are left in place — a re-upload after deploy puts them at the correct path. Cleanup of orphans deferred.
1 parent 2079fa4 commit 0605614

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

Zero-K.info/Controllers/MapsController.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,21 @@ public ActionResult UploadResource(HttpPostedFileBase file, bool specialMap)
452452
{
453453
if (res.Status != UnitSyncer.ResourceFileStatus.RegistrationError)
454454
{
455-
var subfolder = (res.ResourceInfo is Map) ? "maps" : "games";
456-
var contentFolder = Path.Combine(Server.MapPath("~/content"), subfolder);
457-
if (!Directory.Exists(contentFolder)) Directory.CreateDirectory(contentFolder);
458-
459455
// refresh mirrors (local + springfiles)
460456
using (var db = new ZkDataContext())
461457
{
462458
var resource = db.Resources.FirstOrDefault(x => x.InternalName == res.ResourceInfo.Name);
459+
460+
// Subfolder from DB type. Don't use `res.ResourceInfo is Map`: on the
461+
// AlreadyExists path the archive cache hands us a plain ResourceInfo (not
462+
// the Map subclass), so that check is silently false and files land in
463+
// /content/games/ instead of /content/maps/ — see issue #3057.
464+
var isMap = resource?.TypeID == ResourceType.Map
465+
|| (resource == null && res.ResourceInfo is Map);
466+
var subfolder = isMap ? "maps" : "games";
467+
var contentFolder = Path.Combine(Server.MapPath("~/content"), subfolder);
468+
if (!Directory.Exists(contentFolder)) Directory.CreateDirectory(contentFolder);
469+
463470
// case-insensitive FileName match: DB row may have different casing than the
464471
// freshly-uploaded file (springfiles vs original-upload casing) — see issue #3052
465472
var contentFile = resource?.ResourceContentFiles.FirstOrDefault(

0 commit comments

Comments
 (0)