Improve error messages output by buffer_copy() pu/fix-buffer-copy-errmsg
authorRaphaël Hertzog <hertzog@debian.org>
Fri, 8 Apr 2011 22:54:30 +0000 (00:54 +0200)
committerRaphaël Hertzog <hertzog@debian.org>
Fri, 8 Apr 2011 23:30:45 +0000 (01:30 +0200)
Those error messages are often seen by users and they are very difficult
to understand both because they are poorly written and because they
are badly translated. The translations are difficult to get right because
they are a combination of 2 separate strings.

To improve the situation, the messages coming from buffer_copy()
are shorter and do not mention the action ("buffer copy"), instead
we rely on the callers (fd_fd_copy(), fd_null_copy(), fd_vbuf_copy(),
fd_md5()) to provide more explanation on what they are trying to do.

It's important for callers to embed the eventual filenames in the error
message to make it actually useful.

A large number of strings have thus been updated. I also added
comments for the translators so that they are aware of how the strings
are combined.

13 files changed:
dpkg-deb/build.c
dpkg-deb/extract.c
dpkg-deb/info.c
dpkg-split/join.c
dpkg-split/queue.c
dpkg-split/split.c
lib/dpkg/ar.c
lib/dpkg/buffer.c
lib/dpkg/compress.c
src/archives.c
src/configure.c
src/divertcmd.c
src/processarc.c

index 0e40222..fc0faa4 100644 (file)
@@ -469,7 +469,6 @@ do_build(const char *const *argv)
   if (unlink(tfbuf))
     ohshit(_("failed to unlink temporary file (%s), %s"), _("control member"),
            tfbuf);
-  free(tfbuf);
 
   /* And run gzip to compress our control archive. */
   c2 = subproc_fork();
@@ -496,7 +495,11 @@ do_build(const char *const *argv)
             (intmax_t)controlstab.st_size);
     if (fd_write(arfd, versionbuf, strlen(versionbuf)) < 0)
       ohshite(_("error writing `%s'"), debar);
-    fd_fd_copy(gzfd, arfd, -1, _("control member"));
+
+    /* TRANSLATORS: Substituted into "<problem description> while %s",
+     * search "buffer_copy() error message" to see complete strings. */
+    fd_fd_copy(gzfd, arfd, -1, _("copying the control member '%s' into '%s'"),
+               tfbuf, debar);
   } else {
     const char deb_magic[] = ARCHIVEVERSION "\n";
 
@@ -504,6 +507,7 @@ do_build(const char *const *argv)
     dpkg_ar_member_put_mem(debar, arfd, DEBMAGIC, deb_magic, strlen(deb_magic));
     dpkg_ar_member_put_file(debar, arfd, ADMINMEMBER, gzfd, -1);
   }
+  free(tfbuf);
 
   /* Control is done, now we need to archive the data. Start by creating
    * a new temporary file. Immediately unlink the temporary file so others
index 970c623..a6d5b3e 100644 (file)
@@ -174,8 +174,11 @@ extracthalf(const char *debar, const char *dir, const char *taroption,
       } else if (arh.ar_name[0] == '_') {
         /* Members with ‘_’ are noncritical, and if we don't understand
          * them we skip them. */
+        /* TRANSLATORS: Substituted into "<problem description> while %s",
+         * search "buffer_copy() error message" to see complete strings. */
         fd_null_copy(arfd, memberlen + (memberlen & 1),
-                     _("skipped archive member data from %s"), debar);
+                     _("skipping ar member '%s' from '%s'"),
+                     arh.ar_name, debar);
       } else {
        if (strncmp(arh.ar_name, ADMINMEMBER, sizeof(arh.ar_name)) == 0)
          adminmember = 1;
@@ -201,7 +204,8 @@ extracthalf(const char *debar, const char *dir, const char *taroption,
         }
         if (!adminmember != !admininfo) {
           fd_null_copy(arfd, memberlen + (memberlen & 1),
-                       _("skipped archive member data from %s"), debar);
+                       _("skipping ar member '%s' from '%s'"),
+                       arh.ar_name, debar);
         } else {
           /* Yes! - found it. */
           break;
@@ -238,7 +242,8 @@ extracthalf(const char *debar, const char *dir, const char *taroption,
     } else {
       memberlen = stab.st_size - ctrllennum - strlen(ctrllenbuf) - l;
       fd_null_copy(arfd, ctrllennum,
-                   _("skipped archive control member data from %s"), debar);
+                   _("skipping ar member '%s' from '%s'"), "control",
+                   debar);
     }
 
     if (admininfo >= 2) {
@@ -262,7 +267,11 @@ extracthalf(const char *debar, const char *dir, const char *taroption,
   c1 = subproc_fork();
   if (!c1) {
     close(p1[0]);
-    fd_fd_copy(arfd, p1[1], memberlen, _("failed to write to pipe in copy"));
+    /* TRANSLATORS: Substituted into "<problem description> while %s",
+     * search "buffer_copy() error message" to see complete strings. */
+    fd_fd_copy(arfd, p1[1], memberlen,
+               _("copying ar member '%s' from '%s' to decompressor"),
+               "data.tar", debar);
     if (close(p1[1]))
       ohshite(_("failed to close pipe in copy"));
     exit(0);
index c20466d..04a824e 100644 (file)
@@ -106,7 +106,10 @@ info_spew(const char *debar, const char *dir, const char *const *argv)
 
     fd = open(controlfile.buf, O_RDONLY);
     if (fd >= 0) {
-      fd_fd_copy(fd, 1, -1, _("control file '%s'"), controlfile.buf);
+      /* TRANSLATORS: Substituted into "<problem description> while %s",
+       * search "buffer_copy() error message" to see complete strings. */
+      fd_fd_copy(fd, 1, -1, _("writing control file '%s' to <stdout>"),
+                 controlfile.buf);
       close(fd);
     } else if (errno == ENOENT) {
       fprintf(stderr,
index fc23caf..793f645 100644 (file)
@@ -55,8 +55,15 @@ void reassemble(struct partinfo **partlist, const char *outputfile) {
     fd_in = open(pi->filename, O_RDONLY);
     if (fd_in < 0)
       ohshite(_("unable to (re)open input part file `%.250s'"), pi->filename);
-    fd_null_copy(fd_in, pi->headerlen, _("skipping split package header"));
-    fd_fd_copy(fd_in, fd_out, pi->thispartlen, _("split package part"));
+    /* TRANSLATORS: Substituted into "<problem description> while %s",
+     * search "buffer_copy() error message" to see complete strings. */
+    fd_null_copy(fd_in, pi->headerlen,
+                 _("skipping split package header of '%s'"), pi->filename);
+    /* TRANSLATORS: Substituted into "<problem description> while %s",
+     * search "buffer_copy() error message" to see complete strings. */
+    fd_fd_copy(fd_in, fd_out, pi->thispartlen,
+               _("appending split package part '%s' to '%s'"),
+               pi->filename, outputfile);
     close(fd_in);
 
     printf("%d ",i+1);
index 8f221c7..1faa327 100644 (file)
@@ -181,7 +181,10 @@ do_auto(const char *const *argv)
     if (fd_dst)
       ohshite(_("unable to open new depot file `%.250s'"), p);
 
-    fd_fd_copy(fd_src, fd_dst, refi->filesize, _("extracting split part"));
+    /* TRANSLATORS: Substituted into "<problem description> while %s",
+     * search "buffer_copy() error message" to see complete strings. */
+    fd_fd_copy(fd_src, fd_dst, refi->filesize,
+               _("copying part file '%s' to depot file '%s'"), partfile, p);
 
     if (fsync(fd_dst))
       ohshite(_("unable to sync file '%s'"), p);
index 296d1eb..d150bf2 100644 (file)
@@ -72,7 +72,10 @@ deb_field(const char *filename, const char *field)
 
        /* Parant reads from pipe. */
        varbuf_reset(&buf);
-       fd_vbuf_copy(p[0], &buf, -1, _("package field value extraction"));
+       /* TRANSLATORS: Substituted into "<problem description> while %s",
+        * search "buffer_copy() error message" to see complete strings. */
+       fd_vbuf_copy(p[0], &buf, -1, _("copying the output of '%s %s %s %s'"),
+                    BACKEND, "--field", filename, field);
        varbuf_end_str(&buf);
 
        close(p[0]);
@@ -133,7 +136,9 @@ mksplit(const char *file_src, const char *prefix, off_t maxpartsize,
        if (!S_ISREG(st.st_mode))
                ohshit(_("source file `%.250s' not a plain file"), file_src);
 
-       fd_md5(fd_src, hash, -1, "md5hash");
+       /* TRANSLATORS: Substituted into "<problem description> while %s",
+        * search "buffer_copy() error message" to see complete strings. */
+       fd_md5(fd_src, hash, -1, _("computing MD5 hash of %s"), file_src);
        lseek(fd_src, 0, SEEK_SET);
 
        /* FIXME: Use libdpkg-deb. */
index ec2cd85..7a4338c 100644 (file)
@@ -127,7 +127,10 @@ dpkg_ar_member_put_file(const char *ar_name, int ar_fd,
        dpkg_ar_member_put_header(ar_name, ar_fd, name, size);
 
        /* Copy data contents. */
-       fd_fd_copy(fd, ar_fd, size, _("ar member file (%s)"), name);
+       /* TRANSLATORS: Substituted into "<problem description> while %s",
+        * search "buffer_copy() error message" to see complete strings. */
+       fd_fd_copy(fd, ar_fd, size, _("appending file '%s' as ar member '%s'"),
+                  name, ar_name);
 
        if (size & 1)
                if (fd_write(ar_fd, "\n", 1) < 0)
index 0a6ab19..0a93502 100644 (file)
@@ -191,11 +191,18 @@ buffer_copy(struct buffer_data *read_data, struct buffer_data *write_data,
        }
 
        if (bytesread < 0)
-               ohshite(_("failed to read on buffer copy for %s"), desc);
+               /* TRANSLATORS: buffer_copy() error message */
+               ohshite(_("failed to read while %s"), desc);
        if (byteswritten < 0)
-               ohshite(_("failed in write on buffer copy for %s"), desc);
+               /* TRANSLATORS: buffer_copy() error message */
+               ohshite(_("failed to write while %s"), desc);
        if (limit > 0)
-               ohshit(_("short read on buffer copy for %s"), desc);
+               if (bytesread == 0)
+                       /* TRANSLATORS: buffer_copy() error message */
+                       ohshit(_("unexpected end of input while %s"), desc);
+               else
+                       /* TRANSLATORS: buffer_copy() error message */
+                       ohshit(_("unexpected end of output while %s"), desc);
 
        buffer_done(write_data);
 
index 59c40df..b79bb18 100644 (file)
@@ -74,14 +74,18 @@ fd_fd_filter(int fd_in, int fd_out, const char *desc, const char *file, ...)
 static void DPKG_ATTR_NORET
 decompress_none(int fd_in, int fd_out, const char *desc)
 {
-       fd_fd_copy(fd_in, fd_out, -1, _("%s: decompression"), desc);
+       /* TRANSLATORS: Substituted into "<problem description> while %s",
+        * search "buffer_copy() error message" to see complete strings. */
+       fd_fd_copy(fd_in, fd_out, -1, _("decompressing %s"), desc);
        exit(0);
 }
 
 static void DPKG_ATTR_NORET
 compress_none(int fd_in, int fd_out, int compress_level, const char *desc)
 {
-       fd_fd_copy(fd_in, fd_out, -1, _("%s: compression"), desc);
+       /* TRANSLATORS: Substituted into "<problem description> while %s",
+        * search "buffer_copy() error message" to see complete strings. */
+       fd_fd_copy(fd_in, fd_out, -1, _("compressing %s"), desc);
        exit(0);
 }
 
index 9468bcb..3f2cfa2 100644 (file)
@@ -191,8 +191,11 @@ tarfile_skip_one_forward(struct tarcontext *tc, struct tar_entry *ti)
   if (ti->type == tar_filetype_file) {
     char fnamebuf[256];
 
+    /* TRANSLATORS: Substituted into "<problem description> while %s",
+     * search "buffer_copy() error message" to see complete strings. */
     fd_null_copy(tc->backendpipe, ti->size,
-                 _("skipped unpacking file '%.255s' (replaced or excluded?)"),
+                 _("skipping extracted data for file '%s' "
+                   "(replaced or excluded?)"),
                  path_quote_filename(fnamebuf, ti->name, 256));
     r = ti->size % TARBLKSZ;
     if (r > 0)
@@ -704,10 +707,13 @@ tarobject(void *ctx, struct tar_entry *ti)
     push_cleanup(cu_closefd, ehflag_bombout, NULL, 0, 1, &fd);
     debug(dbg_eachfiledetail, "tarobject file open size=%jd",
           (intmax_t)ti->size);
-    { char fnamebuf[256];
+    { char fnamebuf[256], fnamenewbuf[256];
+    /* TRANSLATORS: Substituted into "<problem description> while %s",
+     * search "buffer_copy() error message" to see complete strings. */
     fd_fd_copy(tc->backendpipe, fd, ti->size,
-               _("backend dpkg-deb during `%.255s'"),
-               path_quote_filename(fnamebuf, ti->name, 256));
+               _("copying extracted data for '%s' to '%s'"),
+               path_quote_filename(fnamebuf, ti->name, 256),
+               path_quote_filename(fnamenewbuf, fnamenewvb.buf, 256));
     }
     r = ti->size % TARBLKSZ;
     if (r > 0)
index e0e5fe5..31d0534 100644 (file)
@@ -476,7 +476,10 @@ md5hash(struct pkginfo *pkg, char *hashbuf, const char *fn)
 
        if (fd >= 0) {
                push_cleanup(cu_closefd, ehflag_bombout, NULL, 0, 1, &fd);
-               fd_md5(fd, hashbuf, -1, _("md5hash"));
+               /* TRANSLATORS: Substituted into "<problem description>
+                * while %s", search "buffer_copy() error message" to see
+                * complete strings. */
+               fd_md5(fd, hashbuf, -1, _("computing MD5 hash of %s"), fn);
                pop_cleanup(ehflag_normaltidy); /* fd = open(cdr.buf) */
                close(fd);
        } else if (errno == ENOENT) {
index 5ea6c65..1c3a7c5 100644 (file)
@@ -223,7 +223,9 @@ file_copy(const char *src, const char *realdst)
 
        /* FIXME: leaves a dangling destination file on error. */
 
-       fd_fd_copy(srcfd, dstfd, -1, _("file copy"));
+       /* TRANSLATORS: Substituted into "<problem description> while %s",
+        * search "buffer_copy() error message" to see complete strings. */
+       fd_fd_copy(srcfd, dstfd, -1, _("copying %s to %s"), src, dst);
 
        close(srcfd);
 
index 33f1a81..a3d0683 100644 (file)
@@ -823,7 +823,9 @@ void process_archive(const char *filename) {
       ohshit(_("corrupted filesystem tarfile - corrupted package archive"));
     }
   }
-  fd_null_copy(p1[0], -1, _("dpkg-deb: zap possible trailing zeros"));
+  /* TRANSLATORS: Substituted into "<problem description> while %s",
+   * search "buffer_copy() error message" to see complete strings. */
+  fd_null_copy(p1[0], -1, _("skipping trailing zeros returned by dpkg-deb"));
   close(p1[0]);
   p1[0] = -1;
   subproc_wait_check(pid, BACKEND " --fsys-tarfile", PROCPIPE);