From af3090e494c5bd14160ba180f8d1951135e9778f Mon Sep 17 00:00:00 2001
From: Calum Lind <calumlind+deluge@gmail.com>
Date: Sat, 28 May 2011 23:06:34 +0100
Subject: [PATCH] Fix errno18

---
 deluge/plugins/autoadd/autoadd/core.py |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/deluge/plugins/autoadd/autoadd/core.py b/deluge/plugins/autoadd/autoadd/core.py
index bfea91e..ebac008 100644
--- a/deluge/plugins/autoadd/autoadd/core.py
+++ b/deluge/plugins/autoadd/autoadd/core.py
@@ -263,9 +263,17 @@ def update_watchdir(self, watchdir_id):
                     copy_torrent_path = watchdir['copy_torrent']
                     log.debug("Moving added torrent file \"%s\" to \"%s\"",
                               os.path.basename(filepath), copy_torrent_path)
-                    os.rename(
-                        filepath, os.path.join(copy_torrent_path, filename)
-                    )
+
+                    copy_torrent_file = os.path.join(copy_torrent_path, filename)
+                    try:
+                        os.rename(filepath, copy_torrent_file)
+                    except OSError, why:
+                        if why.errno == 18:
+                                from shutil import copyfile as shutil_copyfile
+                                shutil_copyfile(filepath, copy_torrent_file)
+                                os.remove(filepath)
+                        else:
+                                raise why
                 else:
                     os.remove(filepath)
 
-- 
1.7.4.1

