Changeset 13852


Ignore:
Timestamp:
Jan 23, 2013, 9:28:35 PM (8 years ago)
Author:
jordan
Message:

(libT) fix red herring issue that tr_mkdirp() was setting errno even if the call succeeded. Add tests to confirm the fix.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rename-test.c

    r13851 r13852  
    103103create_file_with_contents (const char * path, const char * str)
    104104{
     105  int rv;
    105106  FILE * fp;
    106107  char * dir;
     108  const int tmperr = errno;
    107109
    108110  dir = tr_dirname (path);
    109   tr_mkdirp (dir, 0700);
     111  errno = 0;
     112  rv = tr_mkdirp (dir, 0700);
     113  assert (errno == 0);
     114  assert (rv == 0);
    110115  tr_free (dir);
    111116
     
    116121
    117122  sync ();
     123
     124  errno = tmperr;
    118125}
    119126
     
    458465  int i;
    459466  int n;
     467  int rv;
    460468  FILE * fp;
    461469  char * path;
     
    464472fprintf (stderr, "top %s exists %d\n", top, (int)tr_fileExists(top,NULL));
    465473
    466 errno = 0;
     474  errno = 0;
    467475  path = tr_buildPath (top, "files-filled-with-zeroes", NULL);
    468   tr_mkdirp (path, 0700);
     476  rv = tr_mkdirp (path, 0700);
     477  assert (rv == 0);
     478  assert (errno == 0);
    469479fprintf (stderr, "%s:%d %s\n", __FILE__, __LINE__, path);
    470480fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno));
  • trunk/libtransmission/utils.c

    r13708 r13852  
    548548    char *      p, * pp;
    549549    struct stat sb;
    550     int         done;
     550    bool        done;
     551    int         tmperr;
     552    int         rv;
    551553
    552554    /* walk past the root */
     
    556558
    557559    pp = p;
    558     done = 0;
    559     while ((p =
    560                 strchr (pp, TR_PATH_DELIMITER)) || (p = strchr (pp, '\0')))
     560    done = false;
     561    while ((p = strchr (pp, TR_PATH_DELIMITER)) || (p = strchr (pp, '\0')))
    561562    {
    562563        if (!*p)
    563             done = 1;
     564            done = true;
    564565        else
    565566            *p = '\0';
    566567
    567         if (stat (path, &sb))
     568        tmperr = errno;
     569        rv = stat (path, &sb);
     570        errno = tmperr;
     571        if (rv)
    568572        {
    569573            /* Folder doesn't exist yet */
    570574            if (tr_mkdir (path, permissions))
    571575            {
    572                 const int err = errno;
    573                 tr_err (_(
    574                            "Couldn't create \"%1$s\": %2$s"), path,
    575                        tr_strerror (err));
     576                tmperr = errno;
     577                tr_err (_("Couldn't create \"%1$s\": %2$s"), path, tr_strerror (tmperr));
    576578                tr_free (path);
    577                 errno = err;
     579                errno = tmperr;
    578580                return -1;
    579581            }
Note: See TracChangeset for help on using the changeset viewer.