Hi
I had some time today and I decided to write a simple patch that fixes
GetAppConfigDir, adhering to basedir-spec.
The arguments after adhering to basedir-spec are:
- The idea to place things within .config/ seems sensible.
- On my system (Debian testing) I see two things that adhere to it
(xfce4 and graveman), so the spec is not completely unknown.
So my patch follows Danny's advice and adheres to basedir-spec.
So GetAppConfigDir(false) and GetAppConfigFile(false, ...) behavior
changes to use $XDG_CONFIG_HOME or ~/.config/. The patch also fixes
GetAppConfigFile(false) behavior (ConfigExtension was not appended in
this case).
I'm attaching the patch to rtl/unix/sysutils.pp (done versus trunk, but
I think it should be merged with 2.0.1 branch too) as file
sysutils.patch, and I'm attaching a trivial test program
test_app_config_dir.pas to easily test GetAppConfigXxx
routines.
Michalis
Index: sysutils.pp
===================================================================
--- sysutils.pp (wersja 1718)
+++ sysutils.pp (kopia robocza)
@@ -1086,13 +1086,24 @@
Result:=IncludeTrailingPathDelimiter(Result);
end;
+{ Follows base-dir spec,
+ see [http://freedesktop.org/Standards/basedir-spec].
+ Always ends with PathDelim. }
+Function XdgConfigHome : String;
+begin
+ Result := GetEnvironmentVariable('XDG_CONFIG_HOME');
+ if Result = '' then
+ Result := GetHomeDir + '.config/' else
+ Result := IncludeTrailingPathDelimiter(Result);
+end;
+
Function GetAppConfigDir(Global : Boolean) : String;
begin
If Global then
Result:=SysConfigDir
else
- Result:=GetHomeDir+ApplicationName;
+ Result:=XdgConfigHome + ApplicationName;
end;
Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
@@ -1114,8 +1125,7 @@
end
else
begin
- Result:=GetHomeDir;
- Result:=Result+'.'+ApplicationName;
+ Result:=XdgConfigHome + ApplicationName + ConfigExtension;
end;
end;
end;
program test_get_app_config;
uses SysUtils;
begin
Writeln('Global config dir : ' , GetAppConfigDir(true));
Writeln('Global config file : ' , GetAppConfigFile(true));
Writeln('Global config file (in subdir) : ' , GetAppConfigFile(true, true));
Writeln('User''s config dir : ', GetAppConfigDir(false));
Writeln('User''s config file : ', GetAppConfigFile(false));
Writeln('User''s config file (in subdir) : ', GetAppConfigFile(false, true));
end.
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel