The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: thfr on January 19, 2024, 03:06:48 PM

Title: pakinstaller fails to extract pak192.comic 0.6 (on OpenBSD)
Post by: thfr on January 19, 2024, 03:06:48 PM
Hi,

When working with the pakinstaller (the one on launch when no existing pakset found), after patch (https://github.com/aburch/simutrans/commit/5fea9a5b53d0899750cc298fdc155d4bf8404001) I can install the paksets except for pak192.comic. What happens with the latter is the downloader works (I can see the created temporary file in ~/simutrans/paksets/ during download), but then nothing is installed and the file disappears again. After some debugging I found errors on extraction of the zip file (ENOENT, I think). It turns out that the zip file for pak192.comic doesn't list the directories before the files in them like the other paksets seem to be doing.

The following diff fixes the issue and allows me to install pak192.comic from the pakinstaller:
Index: src/simutrans/dataobj/pakset_downloader.cc
--- src/simutrans/dataobj/pakset_downloader.cc.orig
+++ src/simutrans/dataobj/pakset_downloader.cc
@@ -161,12 +162,40 @@ static void extract_pak_from_zip(const char* zipfile)
  int isdir = zip_entry_isdir(zip);
  const char* name = zip_entry_name(zip) + (has_simutrans_folder ? 10 : 0);
  if (isdir) {
- // create directory (may fail if exists ...
+ // create directory recursively (may fail if exists ...)
+ char tmp[PATH_MAX];
+ char *p = NULL;
+ size_t len;
+
+ snprintf(tmp, sizeof(tmp), "%s", name);
+ len = strnlen(tmp, sizeof(tmp));
+ if (tmp[len - 1] == '/')
+ tmp[len - 1] = '\0';
+ for (p = tmp + 1; *p; p++)
+ if (*p == '/') {
+ *p = '\0';
+ dr_mkdir(tmp);
+ *p= '/';
+ }
  dr_mkdir(name);
  }
  else {
  // or extract file
  DBG_DEBUG("Install pak file", "%s", name);
+ char tmp[PATH_MAX];
+ char *p = NULL;
+ size_t len;
+
+ snprintf(tmp, sizeof(tmp), "%s", name);
+ len = strnlen(tmp, sizeof(tmp));
+ if (tmp[len - 1] == '/')
+ tmp[len - 1] = '\0';
+ for (p = tmp + 1; *p; p++)
+ if (*p == '/') {
+ *p = '\0';
+ dr_mkdir(tmp);
+ *p= '/';
+ }
  zip_entry_fread(zip, name);
  }
  }

It creates all the higher-level directories for all entries in the zip archive (both dirs and files). This is likely not the ideal diff because it duplicates the code. One consideration to avoid this might be to change dr_mkdir to do this, but as I'm not sure of all the implications of this (dr_mkdir seems to be used a lot), I would like to start with discussing this diff.
Title: Re: pakinstaller fails to extract pak192.comic 0.6 (on OpenBSD)
Post by: prissi on January 20, 2024, 05:46:48 AM
Thank you for you test. I will incorporate this. Duplication is not much of a issue, as this only happens here in the installer. But it would be also acceptable if dr_mkdir creating more than one directory. (On windows, the OS function does this anyway, so maybe therefore the bug did not surface.)

That error has probably stopped installation of pak192 in Android too. r11049 includes a recursive mkdir.
Title: Re: pakinstaller fails to extract pak192.comic 0.6 (on OpenBSD)
Post by: Yona-TYT on January 22, 2024, 01:42:19 AM
On Android now the installer list is empty or broken.

Screenshot_2024-01-21-21-40-36-699_com.simutrans.jpg
Title: Re: pakinstaller fails to extract pak192.comic 0.6 (on OpenBSD)
Post by: Andarix on January 22, 2024, 07:33:56 PM
mmh

my android nightly r11049 show the list on my table (not install works)
Title: Re: pakinstaller fails to extract pak192.comic 0.6 (on OpenBSD)
Post by: prissi on January 23, 2024, 02:31:15 AM
pak192 cannot download on Android since http access is refused by github.
Title: Re: pakinstaller fails to extract pak192.comic 0.6 (on OpenBSD)
Post by: Yona-TYT on January 29, 2024, 02:00:42 PM
Quote from: prissi on January 23, 2024, 02:31:15 AMpak192 cannot download on Android since http access is refused by github.
It is not especially about pak192.comic, in fact no pakset is showing in the download manager list.