Why does rename () return false even though the file has successfully moved to the NFS installation disk?

I get an Invalid argument warning when moving a file from a local drive to an NFS mounted drive. The file was moved successfully despite the error message:

Warning: rename(/tmp/image.jpg,/mnt/remote.server-disk1/image.jpg): Invalid argument

Installed Disk:

 $ df remote.server:/disk1 917G 269M 871G 1% /mnt/remote.server-disk1 

Exported disk on a remote server:

 $ cat /etc/exports /disk1 remote.server(rw,sync,root_squash,secure,crossmnt,anonuid=504,anongid=504) 

File on local disk before renaming ():

 $ stat /tmp/image.jpg File: `image.jpg' Size: 2105 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 33556339 Links: 1 Access: (0777/-rwxrwxrwx) Uid: ( 501/ apache) Gid: ( 501/ apache) ... 

File on the remote drive after renaming ():

 $ stat /disk1/image.jpg File: `image.jpg' Size: 2105 Blocks: 8 IO Block: 4096 regular file Device: 821h/2081d Inode: 34603214 Links: 1 Access: (0777/-rwxrwxrwx) Uid: ( 501/ apache) Gid: ( 501/ apache) ... 

Any ideas? Thanks

+6
source share
3 answers

On Unix you cannot rename or move between file systems ; instead, you must copy the file from one source to the destination, and then delete the source. This will explain the error message you receive. However, it seems incomprehensible why he is still moving. This may be due to permissions or an NFS-mounted drive is locally cached.

+5
source

Maybe because you do it without quotes

rename(/tmp/image.jpg,/mnt/remote.server-disk1/image.jpg);

try adding quotes

rename('/tmp/image.jpg', '/mnt/remote.server-disk1/image.jpg');

0
source

I could not solve this problem, but copy () and then unlink () worked without errors.

0
source

Source: https://habr.com/ru/post/957790/


All Articles