News:

Simutrans Tools
Know our tools that can help you to create add-ons, install and customize Simutrans.

pakinstaller fails to extract pak192.comic 0.6 (on OpenBSD)

Started by thfr, January 19, 2024, 03:06:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

thfr

Hi,

When working with the pakinstaller (the one on launch when no existing pakset found), after patch 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.

prissi

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.

Yona-TYT


Andarix

mmh

my android nightly r11049 show the list on my table (not install works)

prissi

pak192 cannot download on Android since http access is refused by github.

Yona-TYT

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.