Simplify how we check for a setup.rc settings file in the local cache dir (Who knew that setup even did this?): pass the directory down to UserSettings::open_settings() as a parameter, rather than by storing it in an (otherwise unused) member.
Also: rename the 'cwd' parameter, because it's actually an arbitrary directory, not the cwd. (Archeology seems to indicate that at one stage we'd save settings in the cwd if we needed to write them before the cygwin root was known, and migrate that file to the cygwin root when it becomes known; then we changed to keeping that file in the cache dir, then we forgot to migrate it, so perhaps all this complexity isn't needed?) --- UserSettings.cc | 12 +++++++----- UserSettings.h | 4 +--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/UserSettings.cc b/UserSettings.cc index c8ddd3d..3ec6798 100644 --- a/UserSettings.cc +++ b/UserSettings.cc @@ -65,14 +65,17 @@ UserSettings::extend_table (ssize_t i) } io_stream * -UserSettings::open_settings (const char *filename, std::string &pathname) +UserSettings::open_settings (const char *filename, std::string &dir, std::string &pathname) { + // first look for a settings file in specified dir pathname = "file://"; - pathname += cwd; - if (!isdirsep (cwd[cwd.size () - 1]) && !isdirsep (filename[0])) + pathname += dir; + if (!isdirsep (dir[dir.size () - 1]) && !isdirsep (filename[0])) pathname += "/"; pathname += filename; io_stream *f = io_stream::open(pathname, "rt", 0); + + // if not found, look in cygwin installation if (!f) { pathname = "cygfile:///etc/setup/"; @@ -92,8 +95,7 @@ UserSettings::UserSettings () void UserSettings::load (std::string local_dir) { - cwd = local_dir; - io_stream *f = open_settings ("setup.rc", filename); + io_stream *f = open_settings ("setup.rc", local_dir, filename); if (!f) return; diff --git a/UserSettings.h b/UserSettings.h index 3de06e1..dc06ab2 100644 --- a/UserSettings.h +++ b/UserSettings.h @@ -27,7 +27,6 @@ private: ssize_t table_len; std::string filename; - std::string cwd; public: static class UserSettings *global; @@ -44,8 +43,7 @@ public: private: void extend_table (ssize_t); - io_stream *open_settings (const char *, std::string&); - + io_stream *open_settings (const char *, std::string &, std::string&); }; #endif // SETUP_USERSETTINGS_H -- 2.43.0