Merge lp:~mandel/ubuntuone-windows-installer/u1sync_long_paths into lp:ubuntuone-windows-installer/beta

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 134
Merged at revision: 112
Proposed branch: lp:~mandel/ubuntuone-windows-installer/u1sync_long_paths
Merge into: lp:ubuntuone-windows-installer/beta
Diff against target: 134 lines (+19/-14)
5 files modified
src/u1sync/client.py (+7/-6)
src/u1sync/merge.py (+1/-1)
src/u1sync/metadata.py (+7/-3)
src/u1sync/scan.py (+3/-3)
src/u1sync/sync.py (+1/-1)
To merge this branch: bzr merge lp:~mandel/ubuntuone-windows-installer/u1sync_long_paths
Reviewer Review Type Date Requested Status
Ubuntu One hackers Pending
Review via email: mp+39901@code.launchpad.net

Description of the change

Allow u1sync to use long pats by using \\?\

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/u1sync/client.py'
2--- src/u1sync/client.py 2010-09-27 17:33:52 +0000
3+++ src/u1sync/client.py 2010-11-02 21:57:45 +0000
4@@ -565,15 +565,15 @@
5 """Downloads a file from the server."""
6 # file names have to be quoted to make sure that no issues occur when
7 # spaces exist
8- partial_filename = "%s.u1partial" % filename
9- output = open(partial_filename, "w")
10+ partial_filename = "\\\\?\\%s.u1partial" % filename
11+ output = open(partial_filename, "wb")
12
13 @log_timing
14 def rename_file():
15 """Renames the temporary file to the final name."""
16 output.close()
17 print "Finished downloading %s" % filename
18- os.rename(partial_filename, filename)
19+ os.rename(partial_filename, "\\\\?\\" + filename)
20
21 @log_timing
22 def delete_file():
23@@ -688,9 +688,9 @@
24 self.compressed_size += len(compressed_bytes)
25 self.stream.write(compressed_bytes)
26
27- with open(unique_filename, "w+") as compressed:
28- os.unlink(unique_filename)
29- with open(filename, "r") as original:
30+
31+ with open("\\\\?\\" + unique_filename, "wb+") as compressed:
32+ with open("\\\\?\\" + filename, "rb") as original:
33 staging = StagingFile(compressed)
34 shutil.copyfileobj(original, staging)
35 staging.finish()
36@@ -701,6 +701,7 @@
37 staging.crc32,
38 staging.size, staging.compressed_size,
39 compressed)
40+ os.unlink("\\\\?\\" + unique_filename)
41
42 @log_timing
43 def move(self, share_uuid, parent_uuid, name, node_uuid):
44
45=== modified file 'src/u1sync/merge.py'
46--- src/u1sync/merge.py 2010-08-27 14:43:32 +0000
47+++ src/u1sync/merge.py 2010-11-02 21:57:45 +0000
48@@ -42,7 +42,7 @@
49 old_local_node, local_node, old_remote_node, remote_node = nodes
50 # pylint: disable-msg=W0612
51 (parent_path, parent_type) = partial_parent
52- path = os.path.join(parent_path, name.encode("utf-8"))
53+ path = os.path.join(parent_path, name)
54 node_type = merge_action.get_node_type(old_local_node=old_local_node,
55 local_node=local_node,
56 old_remote_node=old_remote_node,
57
58=== modified file 'src/u1sync/metadata.py'
59--- src/u1sync/metadata.py 2010-08-27 14:43:32 +0000
60+++ src/u1sync/metadata.py 2010-11-02 21:57:45 +0000
61@@ -116,7 +116,7 @@
62 def read_string_file(filename, default_value=None):
63 """Reads a string from a file, discarding the final character."""
64 try:
65- with open(filename, "r") as stream:
66+ with open(filename, "rb") as stream:
67 return stream.read()[:-1]
68 except IOError, e:
69 if e.errno != ENOENT:
70@@ -126,7 +126,7 @@
71 def read_uuid_file(filename, default_value=None):
72 """Reads a UUID from a file."""
73 try:
74- with open(filename, "r") as stream:
75+ with open(filename, "rb") as stream:
76 return uuid.UUID(stream.read()[:-1])
77 except IOError, e:
78 if e.errno != ENOENT:
79@@ -138,8 +138,12 @@
80 """Returns a context manager for atomically updating a file."""
81 temp_filename = "%s.%s" % (filename, uuid.uuid4())
82 try:
83- with open(temp_filename, "w") as stream:
84+ with open(temp_filename, "wb") as stream:
85 yield stream
86+ if os.path.exists(filename):
87+ # windows does not have atomic updates
88+ # of files
89+ os.remove(filename)
90 os.rename(temp_filename, filename)
91 finally:
92 safe_unlink(temp_filename)
93
94=== modified file 'src/u1sync/scan.py'
95--- src/u1sync/scan.py 2010-08-27 14:43:32 +0000
96+++ src/u1sync/scan.py 2010-11-02 21:57:45 +0000
97@@ -75,13 +75,13 @@
98 return MergeNode(node_type=SYMLINK, content_hash=content_hash)
99 elif child_names is not None:
100 # directory
101- child_names = [n for n in child_names if should_sync(n.decode("utf-8"))]
102+ child_names = [n for n in child_names if should_sync(n)]
103 child_paths = [(os.path.join(path, child_name),
104 os.path.join(display_path, child_name)) \
105 for child_name in child_names]
106 children = [scan_directory(child_path, child_display_path, quiet) \
107 for (child_path, child_display_path) in child_paths]
108- unicode_child_names = [n.decode("utf-8") for n in child_names]
109+ unicode_child_names = [n for n in child_names]
110 children = dict(zip(unicode_child_names, children))
111 return MergeNode(node_type=DIRECTORY, children=children)
112 else:
113@@ -96,7 +96,7 @@
114 sum.update(bytes)
115
116
117- with open(path, "r") as stream:
118+ with open("\\\\?\\" + path, "rb") as stream:
119 shutil.copyfileobj(stream, HashStream())
120 content_hash = "sha1:%s" % sum.hexdigest()
121 return MergeNode(node_type=FILE, content_hash=content_hash)
122
123=== modified file 'src/u1sync/sync.py'
124--- src/u1sync/sync.py 2010-08-27 14:43:32 +0000
125+++ src/u1sync/sync.py 2010-11-02 21:57:45 +0000
126@@ -75,7 +75,7 @@
127 (parent_path, parent_display_path, parent_uuid, parent_synced) \
128 = partial_parent
129
130- utf8_name = name.encode("utf-8")
131+ utf8_name = name
132 path = os.path.join(parent_path, utf8_name)
133 display_path = os.path.join(parent_display_path, utf8_name)
134 node_uuid = None

Subscribers

People subscribed via source and target branches

to all changes: