mirror of
https://github.com/transmission/transmission
synced 2025-02-23 14:40:43 +00:00
(libT) fix red herring issue that tr_mkdirp() was setting errno even if the call succeeded. Add tests to confirm the fix.
This commit is contained in:
parent
5fb6ec36de
commit
0daad8b7f6
2 changed files with 26 additions and 14 deletions
|
@ -102,11 +102,16 @@ torrentRenameAndWait (tr_torrent * tor,
|
|||
static void
|
||||
create_file_with_contents (const char * path, const char * str)
|
||||
{
|
||||
int rv;
|
||||
FILE * fp;
|
||||
char * dir;
|
||||
const int tmperr = errno;
|
||||
|
||||
dir = tr_dirname (path);
|
||||
tr_mkdirp (dir, 0700);
|
||||
errno = 0;
|
||||
rv = tr_mkdirp (dir, 0700);
|
||||
assert (errno == 0);
|
||||
assert (rv == 0);
|
||||
tr_free (dir);
|
||||
|
||||
remove (path);
|
||||
|
@ -115,6 +120,8 @@ create_file_with_contents (const char * path, const char * str)
|
|||
fclose (fp);
|
||||
|
||||
sync ();
|
||||
|
||||
errno = tmperr;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -457,15 +464,18 @@ create_zero_torrent_partial_contents (const char * top)
|
|||
{
|
||||
int i;
|
||||
int n;
|
||||
int rv;
|
||||
FILE * fp;
|
||||
char * path;
|
||||
char buf[32];
|
||||
|
||||
fprintf (stderr, "top %s exists %d\n", top, (int)tr_fileExists(top,NULL));
|
||||
|
||||
errno = 0;
|
||||
errno = 0;
|
||||
path = tr_buildPath (top, "files-filled-with-zeroes", NULL);
|
||||
tr_mkdirp (path, 0700);
|
||||
rv = tr_mkdirp (path, 0700);
|
||||
assert (rv == 0);
|
||||
assert (errno == 0);
|
||||
fprintf (stderr, "%s:%d %s\n", __FILE__, __LINE__, path);
|
||||
fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno));
|
||||
tr_free (path);
|
||||
|
|
|
@ -547,7 +547,9 @@ tr_mkdirp (const char * path_in,
|
|||
char * path = tr_strdup (path_in);
|
||||
char * p, * pp;
|
||||
struct stat sb;
|
||||
int done;
|
||||
bool done;
|
||||
int tmperr;
|
||||
int rv;
|
||||
|
||||
/* walk past the root */
|
||||
p = path;
|
||||
|
@ -555,26 +557,26 @@ tr_mkdirp (const char * path_in,
|
|||
++p;
|
||||
|
||||
pp = p;
|
||||
done = 0;
|
||||
while ((p =
|
||||
strchr (pp, TR_PATH_DELIMITER)) || (p = strchr (pp, '\0')))
|
||||
done = false;
|
||||
while ((p = strchr (pp, TR_PATH_DELIMITER)) || (p = strchr (pp, '\0')))
|
||||
{
|
||||
if (!*p)
|
||||
done = 1;
|
||||
done = true;
|
||||
else
|
||||
*p = '\0';
|
||||
|
||||
if (stat (path, &sb))
|
||||
tmperr = errno;
|
||||
rv = stat (path, &sb);
|
||||
errno = tmperr;
|
||||
if (rv)
|
||||
{
|
||||
/* Folder doesn't exist yet */
|
||||
if (tr_mkdir (path, permissions))
|
||||
{
|
||||
const int err = errno;
|
||||
tr_err (_(
|
||||
"Couldn't create \"%1$s\": %2$s"), path,
|
||||
tr_strerror (err));
|
||||
tmperr = errno;
|
||||
tr_err (_("Couldn't create \"%1$s\": %2$s"), path, tr_strerror (tmperr));
|
||||
tr_free (path);
|
||||
errno = err;
|
||||
errno = tmperr;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue