Recent

Author Topic: Create files without lunching the program as superuser  (Read 10356 times)

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Create files without lunching the program as superuser
« on: June 28, 2010, 06:49:52 am »
Hello,
I'm asking this question for those who know Linux systems  :D
Please, when I lunch my program created in Lazarus, and my program create files in some directories, while creating these files, I receive an error message saying "Unable to create file '........../..../...py' " note that I use the command "MemoX.Savetofile('xxxxxxxx/xxxx/xx.py')"
Please HELP  :'(
Thanks
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Create files without lunching the program as superuser
« Reply #1 on: June 28, 2010, 06:59:57 am »
Hello,
I'm asking this question for those who know Linux systems  :D
Please, when I lunch my program created in Lazarus
Only at lunch, or also at dinner?  :)

and my program create files in some directories,

What directory? Please specify.

while creating these files, I receive an error message saying "Unable to create file '........../..../...py' " note that I use the command "MemoX.Savetofile('xxxxxxxx/xxxx/xx.py')"

Please quote the exact error message.
Do I understand correctly that the filename in the errormessage is different from the filename specified in the code?

What value does GetLastOSError return?

Bart

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Re: Create files without lunching the program as superuser
« Reply #2 on: June 28, 2010, 07:23:02 am »
Hello, i didn't eat my breakfast, that's why I make some writing mistakes  :D
Any way, Here is the thing, in my program µ.dev, when the user launch the code, my program creates the next file: GetAppConfigDir(True)+'file.py'
here is the full code: pypath := Memo1.Text;
SynEdit1.Lines.SaveToFile(temp1);
SynEdit1.BlockBegin:= SynEdit1.CaretXY;
if not (pypath = '') then
begin
if aa = false then
 begin
       Process1.CommandLine:= pypath + ' '+temp1;
       Process1.Execute;

       end
 else
       Process1.CommandLine:= temp1;
       Process1.Execute;
 end
else
 MessageDlg('No Python path selected',mtCustom, [mbOK], 0);
end;     

When i press the "Launch" button I receive the next error message: «Unable to create file "etc/u.dev/file.py" press OK to ignore the risk data corruption Press Cancel to quit the program»
I'm under Ubuntu 10.2
Please HELP  %)
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

Laksen

  • Hero Member
  • *****
  • Posts: 755
    • J-Software
Re: Create files without lunching the program as superuser
« Reply #3 on: June 28, 2010, 02:06:58 pm »
GetAppConfigDir(true) returns the global dir for application configuration files. You generally need elevated privileges to write in this directory in all operating systems

What you probably want is either a temp dir(GetTempDir/GetTempFileName) or the user local application config directory(GetAppConfigDir(false))

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Re: Create files without lunching the program as superuser
« Reply #4 on: June 29, 2010, 04:35:08 am »
Thanks , and this meen that there is no way to solve my probleme but launch the program as super-user  :-\ ...
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Create files without lunching the program as superuser
« Reply #5 on: June 29, 2010, 05:35:33 am »
Thanks , and this meen that there is no way to solve my probleme but launch the program as super-user  :-\ ...

No: This mean that your program doesn't use the appropriate directories. The way to solve your problem is to use different file distribution. Think about why does your program need to create these files, then decide where to create them.

BTW if your application needs to save configuration, it should save it in the user's work directory (/home/<user> in Linux, C:/Documents and settings/<user> in Windows, etc.). Global configuration should be created by the system administrator and it shouldn't be modified by your program. Your program should use it only if there isn't an user configuration file.

« Last Edit: June 29, 2010, 05:41:30 am by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Re: Create files without lunching the program as superuser
« Reply #6 on: June 29, 2010, 12:10:28 pm »
is there any way to know the user's work directory ?
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Create files without lunching the program as superuser
« Reply #7 on: June 29, 2010, 01:10:37 pm »
GetEnvironmentVariable('HOME') ?

Bart

Sora-Kun

  • Full Member
  • ***
  • Posts: 162
  • I can smell your presence ...
    • Sora-Kun
Re: Create files without lunching the program as superuser
« Reply #8 on: June 29, 2010, 02:40:16 pm »
euuh, what does this return ? and how can I use it  :(
if nothing suites you, make it your self!
The Revolution, Genesis. The next generation IDE.
If you want to help, PM me.

Made in Lazarus.
Soon, in The WWW.

Laksen

  • Hero Member
  • *****
  • Posts: 755
    • J-Software
Re: Create files without lunching the program as superuser
« Reply #9 on: June 29, 2010, 03:38:45 pm »
What are you saving anyway? Why don't you let the user save the file, or just save it under a temporary filename using GetTempFileName?

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Create files without lunching the program as superuser
« Reply #10 on: June 29, 2010, 09:07:13 pm »
try:
man chmod # for more information
chmod 777 /path/file. #read,write,execute(777)
for any file
chmod 777 -R /path/to/folder/    # -R -recursive
or simple right_click properties and set property :D

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Create files without lunching the program as superuser
« Reply #11 on: June 29, 2010, 11:49:33 pm »
is there any way to know the user's work directory ?

Use GetUserDir function.

The HOME environment variable doesn't exists in some systems (i.e. Windows, DOS, OS/2, etc.).
« Last Edit: June 29, 2010, 11:59:13 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Create files without lunching the program as superuser
« Reply #12 on: June 30, 2010, 02:16:10 am »
euuh, what does this return ? and how can I use it  :(
Euuh, it returns the users work directory (at least on linux, which you were asking about).

Bart

 

TinyPortal © 2005-2018