PDA

View Full Version : copying procedure, step by step advice plz.


bazz
08-05-2005, 01:40 PM
Hi,

I am copying a directory with the code,

system ("cp -r /domains/wibble/wobble");

This works :) but I want also to rename the dir using 'rename ....'

Does the renaming happen after the dir has been put into the new dir or midway between the two? I want to ensure that if two people are doing this process at the same time, that they don't interfere with eqch other's dirs.

(I am thinking along the lines of Flock but that is for files not dirs).

Bazz

FishMonger
08-05-2005, 08:45 PM
Instead of doing it in 2 steps via system calls, have you looked at using one of the copy modules?

http://search.cpan.org/~dmuey/File-Copy-Recursive-0.08/Recursive.pm
http://search.cpan.org/~cwest/ppt-0.14/bin/cp
http://search.cpan.org/~eric/OpenPlugin-0.11/inc/File/NCopy.pm

bazz
08-06-2005, 03:39 PM
Hi FishMonger,

I read all of those previously and I have done it with what is your middle suggestion :)

The potential difficulty I still might have is this....

Two clients copy the default Dir very closely together (timewise). I need to ensure that the renaming of the dir for client 1, always takes place before client 2 copies the same dir to the same place, otherwise there could be a conflict.

here's my code

system ("cp -r /domains/123/8765/html/STORE/FILES/$businessType/$businessSubType/TEMPLATE1 /domains/123/8765/html/FILES/Accommodation/");
my $clientDirName = join "_", $businessName, $businessType, $businessSubType, $businessCat, $businessLocalRegion, $county;
my $oldName = "/domains/574/1617/html/FILES/$businessType/TEMPLATE1";
my $newName = "/domains/574/1617/html/FILES/$businessType/$clientDirName";
print qq(
oldName = $oldName<br />
newName =$newName<br />

);
rename ($oldName, $newName) || warn "couldn't rename file";



Bazz

FishMonger
08-06-2005, 07:15 PM
I'm a little confussed.

You said that you're using my second suggestion but you're using a system call and using the shell's cp command which is what I was suggesting NOT to do.

Shouldn't the clients be allowed to copy/rename their own directories and not someone elses?

You could do a file test and only rename the file if it doesn't already exist.

bazz
08-06-2005, 08:48 PM
Sorry FishMonger,

I got confused myself :rolleyes: I'll look again at your links but maybe I have clarified better here.

There already is a file test :)

one client is not able to amend anothers dir name. I am at the stage of trying to prevent the subscription of two clients conflicting with each other. None can rename another client's Dir.

Here's the procedure.

A new client arrives at the admin form. They select from 5 drop downs or text boxes and hit submit.
Submit causes a dir 'TEMPLATE' to be copied from 'STORE' to 'Accommodation' and renames it to reflect the data entered. (I think it takes milliseconds but dont know how to find out).

However, if two clients had subscribed almost simultaneously, might they not both have copied the TEMPLATE, to 'Accommodation' and therefore both be trying to rename the same TEMPLATE dir because only one could exist.

I cant think of a way around this or understand really if it's an issue.

Bazz