Hi Andreas,
 
What kXR_delete does is within bounds of the, admittedly, somewhat ambiguous definition. The combination O_RDWR|O_CREAT|O_TRUNC does “recreate” the file (I suppose a bad choice of words). To create a “new” file one needs to specify kXR_new which adds in O_EXCL , as one would expect. Also, the behavior identical with unix “cp”.
 
As for the strange code, I do recall that I asked Fabrizio to delete the file if he got any error when opening it and then try again. This would mimic the behavior of the cp command with –f. So, I suspect this is a bug and
 
if ( (cli->LastServerError()->errnum == kXR_NotFound)
should really be
 
if ( (cli->LastServerError()->errnum != kXR_NotFound)
then it would all make sense.
 
Andy
 
P.S. Lukasz, this is in XrdCpWorkLst.cc:50
 
 
From: [log in to unmask] href="mailto:[log in to unmask]">Andreas-Joachim Peters
Sent: Thursday, July 07, 2011 3:10 AM
To: [log in to unmask] href="mailto:[log in to unmask]">xrootd-dev
Subject: kXR_delete & xrdcp -f
 
Hi Andy,
there is some confusion about 'xrdcp -f' .... the documentation says it (re-)creates a file, but if I strace a standard xrootd (3.0.4) it is just an open with
a truncate flag e.g. you just overwrite the existing file.

[pid 32708] lstat("/tmp/t1", {st_mode=S_IFREG|0644, st_size=2007, ...}) = 0
[pid 32708] open("/tmp/t1", O_RDWR|O_CREAT|O_TRUNC, 0664) = 21
[pid 32708] close(21)                   = 0
[pid 32708] open("/tmp/t1", O_RDWR|O_TRUNC) = 21
[pid 32708] fcntl(21, F_DUPFD, 512)     = 512
[pid 32708] close(21)                   = 0
[pid 32708] fcntl(512, F_SETFD, FD_CLOEXEC) = 0
[pid 32708] fstat(512, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
[pid 32708] lstat("/tmp/t1", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
[pid 32708] fstat(512, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
[pid 32708] pwrite(512, "root:x:0:0:root:/root:/bin/bash\n"..., 2007, 0) = 2007
pid 32708] close(512)  

Is that correct? ... because in the protocol documentation it says also:

kXR_delete
        - open a new file, deleting any existing file

Also the client has some weird code, it tries to remove the file if it is not found ....

if ( (cli->LastServerError()->errnum == kXR_NotFound)
           && (options & kXR_delete) ) {
         // We silently try to remove the dest file, ignoring the result
         XrdClientAdmin adm(cli->GetCurrentUrl().GetUrl().c_str());
         if (adm.Connect()) {
            adm.Rm( cli->GetCurrentUrl().File.c_str() );
         }

Cheers Andreas.