0
votes

What we want to achieve is to add a local file to each new workspace that is created.
What I currently do is running a script on the trigger of "form-commit client".

That trigger contains the path on the Client's machine where the workspace should be created but the problem occurs when the user tries to create the workspace on a network drive.

What happens is that the file and the directory are created but only with permissions to "Root" since they both didn't exist before so after the trigger's script is completed perforce can't push the source codes to the directory because it doesn't have permissions(and the user can't edit the directory and the file because of the same reason).

There are two directions from my point of view to solve this problem:
1) make sure that the perl script "mkdir" command creates the directory with the same permissions of the parent directory.(how can i do it?) Irelevant, I asked it in another question on stack overflow.

2) Create the file that the trigger is for only after the "pull" command is done by perforce and the workspace directory was created by perforce(What's the trigger for that)

Thanks in advance,
Max.

Edit: (I was wrong aboth the last bullets, it dosen't work as I thoguht it does)

I did the steps that are suggest in the comment and it doesn't work out.

I suspect that all of this is directly related to perforce service user, so here is the thing:
1) The network drive is mapped in a way that only I can write to my user's folder(+ network admins).

2) The perforce trigger pearl script runs on the perforce server(with admin user I suspect.)

3) When the script creates the folder it gives permissions to me(windows domain user) + UnixPermUid\root + UnixPermGid\root which im not part of those groups.

4) When I do chmod (07777, $dir) or die "couldn't chmod $!"; nothing happens(nor error or permissions given)

5) I can't delete the folder from "Windows explorer" or with a trigger that deletes it.

6) The next steps + the trigger are working good:

  • Create folder manually in "windows explorer".
  • Create a workspace from Perforce client that will be located in the directory from above.
  • The trigger creates the required file in the directory with the correct permissions without chmod.
  • All works perfect

Edit 2: Any ideas for question number 2?

2) Create the file that the trigger is for only after the "pull" command is done by perforce and the workspace directory was created by perforce(What's the trigger for that)

1
for 1) Perl has built-in functions chown and chmod. Call those functions with the proper arguments for your environment after creating the directory with the mkdir function. - stevieb
Hi, thanks for the quick answer, I thought about editing the permissions too based on what I think that it's correct since I'm not the real "owner" of those networks directories I'm a little bit afraid of giving permissions by what I think they should be and prefer to give the same permissions as in the parent. I'm currently looking into getting the parents permissions with "stat" function and using them on the mkdir function. - MaxBk
my ($perms, $uid, $gid) = (stat $dir)[2, 4, 5]; ...then: $perms = sprintf "%04o", $perms & 07777; - stevieb
Ok, here is what happens: When I run the script from my PC(windows) it does everything right. When I run the script as a trigger from perforce, It DOES get the user but doesn't get the groups right and shows me "gid=0" and "uid=0" but still my username has permissions when I check on windows. something is strange here. - MaxBk
Ok looks like im stupid and i forgot that the script runs on windows machine. those commands won't work there since stat isn't giving the right perms and chmod will not work on windows. - MaxBk

1 Answers

0
votes

The solution for it was to call icacls system command to grant permissions to the user who created the work space.

$error = system("icacls $ToWriteToDir /grant domain\\user:(OI)(CI)F /T");

The code above adds full recursive permissions to the user who triggered the script(created a new workspace) to the directory on the network drive.

I posted a related more general question here. I decided to separate into two questions in case that someone will find a more relevant solution for the use case of perforce, or general solution for any kind of service.