Ignore:
Timestamp:
Apr 11, 2015, 10:51:59 AM (6 years ago)
Author:
mikedld
Message:

#5908: Check for tr_loadFile return value instead of errno in tr_variantFromFile

Seems like there could be a defect in uClibc making errno not
thread-local. Don't rely on errno value but check function return value
instead which is a better failure indicator.

Return errors from tr_loadFile and tr_variantFromFile via tr_error.
Fix tr_sessionLoadSettings to not fail on Windows if settings.json
does not exist.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r14479 r14491  
    3333#include "cache.h"
    3434#include "crypto-utils.h"
     35#include "error.h"
     36#include "error-types.h"
    3537#include "fdlimit.h"
    3638#include "file.h"
     
    457459tr_sessionLoadSettings (tr_variant * dict, const char * configDir, const char * appName)
    458460{
    459   int err = 0;
    460461  char * filename;
    461462  tr_variant fileSettings;
    462463  tr_variant sessionDefaults;
    463464  tr_variant tmp;
    464   bool success = false;
     465  bool success;
     466  tr_error * error = NULL;
    465467
    466468  assert (tr_variantIsDict (dict));
     
    481483  /* file settings override the defaults */
    482484  filename = tr_buildPath (configDir, "settings.json", NULL);
    483   err = tr_variantFromFile (&fileSettings, TR_VARIANT_FMT_JSON, filename);
    484   if (!err)
     485  if (tr_variantFromFile (&fileSettings, TR_VARIANT_FMT_JSON, filename, &error))
    485486    {
    486487      tr_variantMergeDicts (dict, &fileSettings);
    487488      tr_variantFree (&fileSettings);
     489      success = true;
     490    }
     491  else
     492    {
     493      success = TR_ERROR_IS_ENOENT (error->code);
     494      tr_error_free (error);
    488495    }
    489496
     
    491498  tr_variantFree (&sessionDefaults);
    492499  tr_free (filename);
    493   success = (err==0) || (err==ENOENT);
    494500  return success;
    495501}
     
    510516  {
    511517    tr_variant fileSettings;
    512     const int err = tr_variantFromFile (&fileSettings, TR_VARIANT_FMT_JSON, filename);
    513     if (!err)
     518    if (tr_variantFromFile (&fileSettings, TR_VARIANT_FMT_JSON, filename, NULL))
    514519      {
    515520        tr_variantMergeDicts (&settings, &fileSettings);
Note: See TracChangeset for help on using the changeset viewer.