Recent

Author Topic: Create directory with 777 permission on Linux  (Read 3978 times)

aidv

  • Full Member
  • ***
  • Posts: 173
Create directory with 777 permission on Linux
« on: August 05, 2015, 04:54:02 am »
I am using ExifTool from the command line to extract meta data and thumbnail image of a couple of photos,
and to be able to extract the thumbnail with ExifTool I need to specify a target path which points to a directory
with 777 permission, apparently.

I create my directories from my Lazarus app using the method ForceDirectory()
and the directory is created properly without a problem, but ExifTool can't write to it due to the permission not being set to 777.

I have tried running a command from my lazarus app with the command
Code: [Select]
sudo chmod 777 "<path to target directory>"but the permission of the target directory is not being properly set.

I only get 767 permission when running the command from my lazarus app, but when running the same command manually from the Terminal, the directory permission gets set to 777 without a problem, and ExifTool can extract the thumbnail to that directory without a problem.

So, my question is: How can I, from my Lazarus app, change the permission of a directory to 777?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Create directory with 777 permission on Linux
« Reply #1 on: August 05, 2015, 06:59:17 am »
You can't execute sudo from your app as it will ask for password in the background unless you display a console where people can type password at. Sudo session has application scope (so if you've ever given a permission from other app it won't be reflected in your app) and lasts for 15 minutes by default. Execute a GUI wrapper such as kdesu[do], gksu[do] or something similar. Certainly the target system must have it installed first.

eric

  • Sr. Member
  • ****
  • Posts: 267
Re: Create directory with 777 permission on Linux
« Reply #2 on: August 05, 2015, 08:24:52 am »
If the directory is being created by the program running with normal user privileges, then you don't need root privilege to change the permissions of the directory. Just use FpChmod http://www.freepascal.org/docs-html/rtl/baseunix/fpchmod.html

aidv

  • Full Member
  • ***
  • Posts: 173
Re: Create directory with 777 permission on Linux
« Reply #3 on: August 05, 2015, 04:26:01 pm »
Ok so what Eric suggested works.

EDIT: I created a new thread regarding ExifTool and the command I try to use, as I find it to be off-topic in respect to this thread.

Thanks guys!



Now I can change the permission of a directory from my Lazarus app, and then manually run ExifTool from the terminal to extract the thumbnail of any photo by running the following command:
Code: [Select]
exiftool -b -Thumbnailimage "path_to_file_A" > "path_to_file_B"
Now the problem I am having is that when I run that command from my lazarus app using the code below, the thumbnail is not extracted.

Is there a fix for it or does anyone know what's happening?

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
  var command_line_results: string;
begin
  RunCommand('exiftool -b -Thumbnailimage "/home/pi/Desktop/myLazApp/photos/img_0001.JPG" > "/home/pi/Desktop/myLazApp/photos/Thumbnails/img_0001.JPG"', [], command_line_results');

  Memo1.Lines.Add(command_line_results); //if the variable "command_line_results" is empty, then exiftool successfully extracted the thumbnail
end;

As the code suggests, if exiftool returns nothing then the thumbnail has been extracted, but when looking inside the directory given as an output, theres nothing there.
But when running the same exiftool command manually, exiftool behaves correctly.

Any suggestions?
« Last Edit: August 05, 2015, 08:33:38 pm by aidv »

hy

  • Full Member
  • ***
  • Posts: 221
Re: Create directory with 777 permission on Linux
« Reply #4 on: August 05, 2015, 10:27:08 pm »
Removed post due to hitting reply on the wrong thread. Sorry for the inconvenience
« Last Edit: August 05, 2015, 10:44:11 pm by hy »
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

 

TinyPortal © 2005-2018