Recent

Author Topic: GetAppConfigDir....  (Read 2295 times)

Mark-

  • New Member
  • *
  • Posts: 22
GetAppConfigDir....
« on: September 21, 2018, 05:46:38 am »
Hello,

I am porting my first program to Linux, a free program.
Learning Linux and Lazarus has been fun.

GetAppConfigDir is...confusing.

"GetAppConfigDir returns the name of a directory in which the application should store its configuration
files on the current OS."

OK, the program settings are global (all users use the same settings) so I pass true and get back a path to "/etc/ <app name>". Now the rub, the user does not have permission to write to that directory. Catch-22.

Why return a directory/path that requires all users to have root access?

Confused. If that is not the directory to create/read/modify configuration settings for all users, regardless of rights, what is the correct directory?

Thanks,

Mark


GetMem

  • Hero Member
  • *****
  • Posts: 3515
Re: GetAppConfigDir....
« Reply #1 on: September 21, 2018, 06:16:55 am »
Hi Mark-,

Lazarus uses the same technique to get the config directory:
Code: Pascal  [Select]
  1. PrimaryConfigPath := ExtractFilePath(ChompPathDelim(GetAppConfigDirUTF8(False))) + 'lazarus';
and is always writable for the current user. For example on my Linux Mint 18.2, returns the following directory: /home/<username>/.config/lazarus.

PS: This was tested extensively in the past few years, so something strange is happening at your side. Please test the above example and let us know if it works or not.

HeavyUser

  • Sr. Member
  • ****
  • Posts: 262
Re: GetAppConfigDir....
« Reply #2 on: September 21, 2018, 06:19:21 am »
Doesn't work that way on multi user systems. It doesn't work that way on windows either. A global setup is usually used for the default settings or the reset to defaults and the user's local folder is used to save user preferences. Usually on those settings are some pretty personal choices, from colors to size and types of fonts etc. As far as I know you are still able to have read only access to that folder regardless of user.

Mark-

  • New Member
  • *
  • Posts: 22
Re: GetAppConfigDir....
« Reply #3 on: September 21, 2018, 06:24:55 am »
Thanks for the response.

> /home/<username>/.config/lazarus.
>GetAppConfigDirUTF8(False)

Right. I do not want that. I want one file for all users, not each user with different settings. GetAppConfigDir(true)

> It doesn't work that way on windows either.

Yes it does. The "C:\ProgramData\<some name>\ directory is available to all users regardless of user permissions.

GetMem

  • Hero Member
  • *****
  • Posts: 3515
Re: GetAppConfigDir....
« Reply #4 on: September 21, 2018, 06:33:27 am »
@Mark-
Quote
Yes it does. The "C:\ProgramData\<some name>\ directory is available to all users regardless of user permissions.
On windows yes, but I'm almost certain there is no such thing in Linux.

Handoko

  • Hero Member
  • *****
  • Posts: 3231
  • My goal: build my own game engine using Lazarus
Re: GetAppConfigDir....
« Reply #5 on: September 21, 2018, 06:47:21 am »
OK, the program settings are global (all users use the same settings) so I pass true and get back a path to "/etc/ <app name>". Now the rub, the user does not have permission to write to that directory. Catch-22.

Why return a directory/path that requires all users to have root access?

Because you're trying to save the settings that affect globally (all users) in the system, so you have to have the permission, root access or sudo. It is for security reason, it's Linux not Windows. The /etc/ folder is readable for all users with or without the special permission. I might be wrong but that's what I know.

Mark-

  • New Member
  • *
  • Posts: 22
Re: GetAppConfigDir....
« Reply #6 on: September 21, 2018, 06:54:55 am »

OK, so where to place a file readable/writable by all users?


Handoko

  • Hero Member
  • *****
  • Posts: 3231
  • My goal: build my own game engine using Lazarus
Re: GetAppConfigDir....
« Reply #7 on: September 21, 2018, 07:01:07 am »
As far as I know there is no such the thing in Linux.
(correct me if I'm wrong).

Yeah, Linux is sometimes stupidly secure. >:(

But if you really want a read/write able folder for all users, you can try:
/tmp/

I've just tested in on Ubuntu, it worked. But I'm sure you know, storing important data in temp folder is stupid too. :D

Mark-

  • New Member
  • *
  • Posts: 22
Re: GetAppConfigDir....
« Reply #8 on: September 21, 2018, 07:09:39 am »
Right from what I read /tmp is cleared at each reboot. Some sources said different events can clear the /tmp directory.

/var/tmp might be possible. I did not try. The name was not appealing.
 :D

GetMem

  • Hero Member
  • *****
  • Posts: 3515
Re: GetAppConfigDir....
« Reply #9 on: September 21, 2018, 07:21:11 am »
Upload to the cloud.  :D Now seriously working against the system will fire back at some point. Linux is not windows, OSX has its own quirks.
Save the config file to the same directory as your application. State in the document that the application folder must be writable and you're good to go.

Bart

  • Hero Member
  • *****
  • Posts: 3546
    • Bart en Mariska's Webstek
Re: GetAppConfigDir....
« Reply #10 on: September 21, 2018, 03:16:29 pm »

OK, so where to place a file readable/writable by all users?

Make a folder somewhere, put the file there, then change persmissions to read/write for all users and groups.
Do this when installing, you muust have root permissions (sudo) to do so anyway.

Not recommended practice on *nix though.