[Gambas-user] COPY does not always copy chgrp and chown

Rolf-Werner Eilert eilert-sprachen at ...221...
Mon Aug 10 10:28:03 CEST 2009


Benoît Minisini schrieb:
>> Just found this (Gambas 2 project) when copying several students from
>> one class into another. For each student, there are about 6 files to be
>> copied from one directory into another. The first one will always get
>> standard chgrp and chown of the application's user. The other files
>> SOMETIMES are copied with correct group and ownership, MOSTLY not.
>>
>> All files have special group and ownership, controlling if teachers or
>> only the office can access the data.
>>
>> Now, this is the function that does the actual copy:
>>
>>
>>
>> 'kopiert alle Dateien eines Namens in eine andere Kartei
>> '- ziel ist der Zielpfad
>> '- wenn eine gleichnamige Datei schon vorhanden ist, kommt "-1" zurück
>> '- wenn es geklappt hat, kommt "0" zurück
>>
>> 'wird z. B. von dlgNamenKopieren benutzt
>>
>> PUBLIC FUNCTION NamenKopieren(schlyssel AS String, ziel AS String) AS
>> Integer
>> DIM original AS String
>> DIM odatei AS String
>> DIM opfad AS String
>> DIM datei AS String
>>
>>    original = getFilename(schlyssel)
>>
>>    odatei = file.BaseName(original)
>>    opfad = file.Dir(original)
>>
>>    IF Exist(ziel &/ odatei & ".felder") THEN
>>      RETURN -1
>>    END IF
>>
>>    FOR EACH datei IN Dir(opfad, odatei & ".*")
>>      COPY opfad &/ datei TO ziel &/ datei
>>    NEXT
>>
>>    RETURN 0
>>
>> END
>>
>>
>> Do you see anything wrong here? As it sometimes works correctly I would
>> actually think that it's a bug in copy.
>>
>> The filesystem is ext3.
>>
>> Regards
>>
>> Rolf
>>
> 
> COPY actually does the same thing as opening the input file, opening the 
> output file, reading the data, writing the data, closing the input gile, 
> closing the output file.
> 
> So the output file will have the same authorizations as the input file, except 
> that they are filtered by the "umask" (man umask) and that the file will be 
> owned by the process who wrote the file.
> 
> COPY is there just for simple cases.
> 
> I suggest you use the "cp" command, using the "--preserve" option.
> 
> Regards,
> 

Ahh - ok. Wouldn't it be possible to pimp COPY giving it a special 
"preserve" option which would take care about this?

Anyway: thanks for the tip! The only other way I know is using chmod and 
chgrp after writing the files. But then you have to use a SHELL anyway, 
so using cp --preserve is much smarter... :-)

Regards

Rolf





More information about the User mailing list