Abstracting configuration directories

I'm writing a small utility whose only non-portable code involves the two paths, /etc/htsnrc $HOME/.htsnrc These have sort-of analogues under Windows; in .NET they are available through something like, Environment.SpecialFolder.CommonApplicationData Environment.SpecialFolder.ApplicationData I personally will only ever need to run on Linux, but as a matter of principle I'd like to abstract the paths. Is there a library that can do this already?

I think this is what you're looking for: http://hackage.haskell.org/package/directory-1.2.0.1/docs/System-Directory.h... Cheers, Tim On Dec 19, 2013, at 4:46 AM, Michael Orlitzky wrote:
I'm writing a small utility whose only non-portable code involves the two paths,
/etc/htsnrc $HOME/.htsnrc
These have sort-of analogues under Windows; in .NET they are available through something like,
Environment.SpecialFolder.CommonApplicationData Environment.SpecialFolder.ApplicationData
I personally will only ever need to run on Linux, but as a matter of principle I'd like to abstract the paths. Is there a library that can do this already? _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 12/19/2013 01:40 AM, Tim C. Schroeder wrote:
I think this is what you're looking for:
http://hackage.haskell.org/package/directory-1.2.0.1/docs/System-Directory.h...
getAppUserDataDirectory will give me the user's configuration directory (ala $HOME/.htsnrc), but not the global one (whatever I'm supposed to use instead of /etc on Windows). A non-default config is necessary for the application to work at all, so it would be nice to be able to install one globally (so each user doesn't have to copy the example and modify it). Then again, until my patches allowing cabal to emit electric shocks are accepted, that may just have to be the punishment for using Windows.

On Thu, 19 Dec 2013 18:15:09 +0100, Michael Orlitzky
On 12/19/2013 01:40 AM, Tim C. Schroeder wrote:
I think this is what you're looking for:
http://hackage.haskell.org/package/directory-1.2.0.1/docs/System-Directory.h...
getAppUserDataDirectory will give me the user's configuration directory (ala $HOME/.htsnrc), but not the global one (whatever I'm supposed to use instead of /etc on Windows).
You could use the environment variable AllUsersProfile[0] for this. The directory package should be extended with a function getAppGlobalDataDirectory. Regards, Henk-Jan van Tuyl [0] http://environmentvariables.org/AllUsersProfile -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

On Fri, 20 Dec 2013 12:29:03 +0100, Henk-Jan van Tuyl
You could use the environment variable AllUsersProfile[0] for this.
Another way to do this: Prelude> :m System.Win32 Prelude System.Win32> sHGetFolderPath nullPtr 35 nullPtr 0 "C:\\Documents and Settings\\All Users\\Application Data" Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

On 12/20/2013 08:13 AM, Henk-Jan van Tuyl wrote:
On Fri, 20 Dec 2013 12:29:03 +0100, Henk-Jan van Tuyl
wrote: You could use the environment variable AllUsersProfile[0] for this.
Another way to do this:
Prelude> :m System.Win32 Prelude System.Win32> sHGetFolderPath nullPtr 35 nullPtr 0 "C:\\Documents and Settings\\All Users\\Application Data"
Thanks, this is what getAppUserDataDirectory (from System.Directory) is doing: getAppUserDataDirectory :: String -> IO FilePath getAppUserDataDirectory appName = do ... s <- Win32.sHGetFolderPath nullPtr Win32.cSIDL_APPDATA nullPtr 0 ... I think your path above is the correct location on Win32; in that case, Windows makes it available[1] as CSIDL_COMMON_APPDATA. System.Win32 doesn't use this constant at the moment, but I think it could go in [2] along with the rest of them. Then, System.Directory could provide getAppGlobalDataDirectory as you suggest. A patch looks easy, but I'm not sure that I would call /etc the "global data directory" on Unix. I'll have to think about it some more. [1] http://msdn.microsoft.com/en-us/library/windows/desktop/bb762494%28v=vs.85%2... [2] http://hackage.haskell.org/package/Win32-2.2.2.0/docs/System-Win32-Shell.htm...

On 12/20/2013 02:09 PM, Michael Orlitzky wrote:
A patch looks easy, but I'm not sure that I would call /etc the "global data directory" on Unix. I'll have to think about it some more.
For posterity, when using Cabal, the system config directory is available via getSysconfDir in build/autogen/Paths_<program>.hs. This puts the responsibility on the person who runs configure, which I kind of like.

Interesting. Is there documentation anywhere about what Cabal puts into the Paths_*.hs files? I couldn't find anything beyond getDataFileName and version :: Version in the Cabal user guide. The link to "prefix independence" refers to a non-existing anchor tag. On 2013-12-22 00:10, Michael Orlitzky wrote:
For posterity, when using Cabal, the system config directory is available via getSysconfDir in build/autogen/Paths_<program>.hs. This puts the responsibility on the person who runs configure, which I kind of like.
-- Joeri van Eekelen - j.v.eekelen@gmail.com

On 12/22/2013 07:48 AM, Joeri van Eekelen wrote:
Interesting. Is there documentation anywhere about what Cabal puts into the Paths_*.hs files? I couldn't find anything beyond getDataFileName and version :: Version in the Cabal user guide. The link to "prefix independence" refers to a non-existing anchor tag.
I don't think so, I found it by accident.

I think the "right" way to accomplish this is through the Paths_pkg module generated by Cabal: http://www.haskell.org/cabal/users-guide/developing-packages.html#accessing-... Specifically, the getDataFile function can be used to look up the actual location of files specified in the data-files: field of the .cabal file. This should even work if someone uses a nonstandard --prefix. On 2013-12-20 12:29, Henk-Jan van Tuyl wrote:
On Thu, 19 Dec 2013 18:15:09 +0100, Michael Orlitzky
wrote: On 12/19/2013 01:40 AM, Tim C. Schroeder wrote:
I think this is what you're looking for:
http://hackage.haskell.org/package/directory-1.2.0.1/docs/System-Directory.h...
getAppUserDataDirectory will give me the user's configuration directory (ala $HOME/.htsnrc), but not the global one (whatever I'm supposed to use instead of /etc on Windows).
You could use the environment variable AllUsersProfile[0] for this.
The directory package should be extended with a function getAppGlobalDataDirectory.
Regards, Henk-Jan van Tuyl
-- Joeri van Eekelen - j.v.eekelen@gmail.com

On 12/20/2013 12:51 PM, Joeri van Eekelen wrote:
I think the "right" way to accomplish this is through the Paths_pkg module generated by Cabal:
http://www.haskell.org/cabal/users-guide/developing-packages.html#accessing-...
This is more for when you want to install a data file and don't care where, but you need to be able to find it later. My configuration file should wind up in a fixed location (e.g. /etc on Linux); I'm just not sure where that is on Windows, and I don't want to have to hard-code it in case it changes in Windows 3000. Thanks for the suggestion though.
participants (5)
-
Colin Adams
-
Henk-Jan van Tuyl
-
Joeri van Eekelen
-
Michael Orlitzky
-
Tim C. Schroeder