File 0001-possibly-truncate-pathname-components.patch of Package wget.34429

Index: wget-1.20.3/src/url.c
===================================================================
--- wget-1.20.3.orig/src/url.c
+++ wget-1.20.3/src/url.c
@@ -1636,6 +1636,50 @@ convert_fname (char *fname)
 }
 #endif
 
+/* Check if the length of path element is acceptable.
+   If it's longer than OS-defined maximum, truncate it. */
+static void
+possibly_truncate_pathel (struct growable *fnres, char *pathel) {
+  size_t len = strlen (pathel);
+  size_t max_length;
+
+#ifdef WINDOWS
+  if (MAX_PATH > (len + CHOMP_BUFFER + 2))
+    {
+      max_length = MAX_PATH - (fnres->tail + CHOMP_BUFFER + 2);
+      /* FIXME: In Windows a filename is usually limited to 255 characters.
+      To really be accurate you could call GetVolumeInformation() to get
+      lpMaximumComponentLength
+
+      Only FAT16 actually uses the 8.3 standard; this shouldn't be worrisome.
+      */
+      if (max_length > 255)
+        {
+          max_length = 255;
+        }
+    }
+  else
+    {
+      max_length = 0;
+    }
+#else
+  max_length = get_max_length (fnres->base, fnres->tail, _PC_NAME_MAX) - CHOMP_BUFFER;
+#endif
+  if (max_length > 0 && len > max_length)
+    {
+      logprintf (LOG_NOTQUIET, "The name is too long, %lu chars total.\n",
+          (unsigned long) len);
+      logprintf (LOG_NOTQUIET, "Trying to shorten...\n");
+
+      /* Truncate path element. */
+      pathel[max_length] = '\0';
+
+      logprintf (LOG_NOTQUIET, "New name is %s.\n", pathel);
+    }
+
+  return;
+}
+
 /* Append to DEST the directory structure that corresponds the
    directory part of URL's path.  For example, if the URL is
    http://server/dir1/dir2/file, this appends "/dir1/dir2".
@@ -1651,7 +1695,7 @@ convert_fname (char *fname)
    Each component of the path is quoted for use as file name.  */
 
 static void
-append_dir_structure (const struct url *u, struct growable *dest)
+append_dir_structure (const struct url *u, struct growable *dest, struct growable *fnres)
 {
   char *pathel, *next;
   int cut = opt.cut_dirs;
@@ -1670,7 +1714,11 @@ append_dir_structure (const struct url *
 
       if (dest->tail)
         append_char ('/', dest);
+
+      *next = '\0';   /* temporarily isolate the next element */
+      possibly_truncate_pathel(fnres, pathel);
       append_uri_pathel (pathel, next, true, dest);
+      *next = '/';
     }
 }
 
@@ -1744,9 +1792,9 @@ url_file_name (const struct url *u, char
             }
         }
 
-      append_dir_structure (u, &temp_fnres);
+      append_dir_structure (u, &temp_fnres, &fnres);
     }
-
+ 
   if (!replaced_filename)
     {
       /* Create the filename. */
@@ -1781,40 +1829,7 @@ url_file_name (const struct url *u, char
   temp_fnres.tail = 0;
   append_string (fname, &temp_fnres);
   xfree (fname);
-
-  /* Check that the length of the file name is acceptable. */
-#ifdef WINDOWS
-  if (MAX_PATH > (fnres.tail + CHOMP_BUFFER + 2))
-    {
-      max_length = MAX_PATH - (fnres.tail + CHOMP_BUFFER + 2);
-      /* FIXME: In Windows a filename is usually limited to 255 characters.
-      To really be accurate you could call GetVolumeInformation() to get
-      lpMaximumComponentLength
-      */
-      if (max_length > 255)
-        {
-          max_length = 255;
-        }
-    }
-  else
-    {
-      max_length = 0;
-    }
-#else
-  max_length = get_max_length (fnres.base, fnres.tail, _PC_NAME_MAX) - CHOMP_BUFFER;
-#endif
-  if (max_length > 0 && strlen (temp_fnres.base) > max_length)
-    {
-      logprintf (LOG_NOTQUIET, "The name is too long, %lu chars total.\n",
-          (unsigned long) strlen (temp_fnres.base));
-      logprintf (LOG_NOTQUIET, "Trying to shorten...\n");
-
-      /* Shorten the file name. */
-      temp_fnres.base[max_length] = '\0';
-
-      logprintf (LOG_NOTQUIET, "New name is %s.\n", temp_fnres.base);
-    }
-
+  possibly_truncate_pathel(&fnres, (&temp_fnres)->base);
   xfree (fname_len_check);
 
   /* The filename has already been 'cleaned' by append_uri_pathel() above.  So,
openSUSE Build Service is sponsored by