From 7223c2821e63d3abd96eb5f50c685a9119618cd1 Mon Sep 17 00:00:00 2001
From: Daira Hopwood <daira@jacaranda.org>
Date: Sun, 7 Jun 2015 14:26:30 +0100
Subject: [PATCH] Teach uploader to use flat hierarchy. refs ticket:2442

Author: David Stainton <david@leastauthority.com>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
---
 src/allmydata/frontends/drop_upload.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/allmydata/frontends/drop_upload.py b/src/allmydata/frontends/drop_upload.py
index 7e2981f8..4e1e970f 100644
--- a/src/allmydata/frontends/drop_upload.py
+++ b/src/allmydata/frontends/drop_upload.py
@@ -1,5 +1,6 @@
 
 import sys, os, stat
+import os.path
 from collections import deque
 
 from twisted.internet import defer, reactor, task
@@ -11,9 +12,8 @@ from allmydata.interfaces import IDirectoryNode, NoSuchChildError, ExistingChild
 from allmydata.util.fileutil import abspath_expanduser_unicode, precondition_abspath
 from allmydata.util.encodingutil import listdir_unicode, to_filepath, \
      unicode_from_filepath, quote_local_unicode_path, FilenameEncodingError
-from allmydata.immutable.upload import FileName
-
-from allmydata import backupdb
+from allmydata.immutable.upload import FileName, Data
+from allmydata import backupdb, magicpath
 
 
 class DropUploader(service.MultiService):
@@ -183,7 +183,9 @@ class DropUploader(service.MultiService):
 
         def _add_dir(ignore, name):
             self._notifier.watch(to_filepath(path), mask=self.mask, callbacks=[self._notify], recursive=True)
-            d2 = self._parent.create_subdirectory(name, overwrite=False)
+            u = Data("", self._convergence)
+            name += "@_"
+            d2 = self._parent.add_file(name, u)
             def _err(f):
                 f.trap(ExistingChildError)
                 self._log("subdirectory %r already exists" % (path,))
@@ -197,7 +199,10 @@ class DropUploader(service.MultiService):
 
         def _maybe_upload(val):
             self._pending.remove(path)
-            name = os.path.basename(path)
+            relpath = os.path.relpath(path, self._local_dir)
+            name = magicpath.path2magic(relpath)
+            # XXX
+            #name = os.path.basename(path)
 
             if not os.path.exists(path):
                 self._log("uploader: not uploading non-existent file.")
-- 
2.45.2