Fix the static problem AGAIN. I know it's nice to use static vars for paths and stuff between threads, but we can't always invoke a new process when debugging, so we have to explicitly allow for resets. This just makes per_user_directory match up with the rest of the code (unix_local_db and friends) ENGINE-633
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Sun, 22 Sep 2019 15:02:37 +0200
branchENGINE-633
changeset 4078516e17803980
parent 4077 7061fa6755ba
child 4079 da3b0627a59c
Fix the static problem AGAIN. I know it's nice to use static vars for paths and stuff between threads, but we can't always invoke a new process when debugging, so we have to explicitly allow for resets. This just makes per_user_directory match up with the rest of the code (unix_local_db and friends)
src/platform_unix.c
test/src/test_util.cc
     1.1 --- a/src/platform_unix.c	Fri Sep 20 11:41:41 2019 +0200
     1.2 +++ b/src/platform_unix.c	Sun Sep 22 15:02:37 2019 +0200
     1.3 @@ -305,11 +305,25 @@
     1.4      free(_new);
     1.5  }
     1.6  
     1.7 -DYNAMIC_API const char *per_user_directory(void)
     1.8 +#ifndef NDEBUG
     1.9 +static const char *_per_user_directory(int reset)
    1.10 +#else 
    1.11 +static const char *_per_user_directory(void)
    1.12 +#endif
    1.13  {
    1.14      static char *path = NULL;
    1.15 +
    1.16 +#ifdef NDEBUG    
    1.17      if (path)
    1.18          return path;
    1.19 +#else        
    1.20 +    if (path && !reset)
    1.21 +        return path;
    1.22 +    else if (path) {
    1.23 +        free(path);
    1.24 +        path = NULL;
    1.25 +    }
    1.26 +#endif    
    1.27  
    1.28      const char *home = NULL;
    1.29  #ifndef NDEBUG
    1.30 @@ -355,10 +369,17 @@
    1.31  #endif
    1.32          return path;
    1.33  
    1.34 -    if (!per_user_directory())
    1.35 +    char* pathret = NULL;
    1.36 +#ifndef NDEBUG 
    1.37 +    pathret = _per_user_directory(reset);
    1.38 +#else 
    1.39 +    pathret = _per_user_directory();
    1.40 +#endif
    1.41 +
    1.42 +    if (!pathret)
    1.43          return NULL;
    1.44  
    1.45 -    path = strdup(per_user_directory());
    1.46 +    path = strdup(pathret);
    1.47      assert(path);
    1.48      if (!path)
    1.49          return NULL;
    1.50 @@ -471,6 +492,15 @@
    1.51      return path;
    1.52  }
    1.53  
    1.54 +DYNAMIC_API const char *per_user_directory(void) {
    1.55 +#ifdef NDEBUG
    1.56 +    return _per_user_directory(void);
    1.57 +#else 
    1.58 +    return _per_user_directory(false);
    1.59 +#endif
    1.60 +}
    1.61 +
    1.62 +
    1.63  static const char *gpg_conf_path = ".gnupg";
    1.64  static const char *gpg_conf_name = "gpg.conf";
    1.65  static const char *gpg_agent_conf_name = "gpg-agent.conf";
    1.66 @@ -707,4 +737,3 @@
    1.67      _empty(&path);
    1.68      return NULL;
    1.69  }
    1.70 -
     2.1 --- a/test/src/test_util.cc	Fri Sep 20 11:41:41 2019 +0200
     2.2 +++ b/test/src/test_util.cc	Sun Sep 22 15:02:37 2019 +0200
     2.3 @@ -33,7 +33,7 @@
     2.4          if (curr_wd.empty())
     2.5              throw std::runtime_error("Error grabbing current working directory"); 
     2.6  
     2.7 -        _main_test_home_dir = curr_wd + "/pEp_test_home";
     2.8 +        _main_test_home_dir = "/tmp/pEp_test_home";
     2.9      }
    2.10      return _main_test_home_dir;        
    2.11  }