Atomic File.copy from Linux to Windows shared drive

Hi all,

We’ve got a Linux box that runs some reports. When the reports are
finished they’re supposed to be copied to a public drive setup via
Samba, with a Samba client on the Linux box and a Samba server setup on
a Windows box somewhere (not available to me). At least, that’s my
understanding of how things are setup. The public drive is mounted as
/X.

The problem is that sometimes the server (or client?) flakes out and
weird stuff happens during File.copy attempts. In the last incident
only parts of files were copied. Some operations seemed to just hang.

Here’s a synopsis of what I attempted most recently:

require ‘ftools’
require ‘timeout’

begin
Timeout.timeout(3){
File.copy(‘temp.txt’, ‘temp.bak’)
File.rename(‘temp.bak’, ‘/X/temp.txt’)
File.unlink(‘temp.bak’)
}
rescue Errno::EPERM

Ignore bogus EPERM errors - harmless

end

The problem is that File.rename is raising Errno::EXDEV errors, and
simply ignoring those won’t work.

So, given that the shared drive could go down in the middle of a
File.copy operation, what are my options here? Would Ara’s posixlock
package help me here? If so, how would I use it? It wasn’t clear to me
from the docs.

Thanks,

Dan

This communication is the property of Qwest and may contain confidential
or
privileged information. Unauthorized use of this communication is
strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and
destroy
all copies of the communication and any attachments.

Ignore bogus EPERM errors - harmless

end

The problem is that File.rename is raising Errno::EXDEV errors, and
simply ignoring those won’t work.

Shouldn’t it be:
File.copy(‘temp.txt’, ‘/X/temp.bak’)
File.rename(’/X/temp.bak’, ‘/X/temp.txt’)