dbox 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/dbox.gemspec +1 -1
- data/lib/dbox.rb +1 -0
- data/lib/dbox/api.rb +13 -15
- data/lib/dbox/db.rb +4 -3
- data/spec/dbox_spec.rb +23 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/dbox.gemspec
CHANGED
data/lib/dbox.rb
CHANGED
data/lib/dbox/api.rb
CHANGED
@@ -48,9 +48,8 @@ module Dbox
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def run(path)
|
51
|
-
path = escape_path(path)
|
52
51
|
begin
|
53
|
-
res = yield
|
52
|
+
res = yield
|
54
53
|
case res
|
55
54
|
when Hash
|
56
55
|
res
|
@@ -71,17 +70,17 @@ module Dbox
|
|
71
70
|
|
72
71
|
def metadata(path = "/")
|
73
72
|
log.debug "Fetching metadata for #{path}"
|
74
|
-
run(path) do
|
75
|
-
@client.metadata(@conf["root"], path)
|
73
|
+
run(path) do
|
74
|
+
@client.metadata(@conf["root"], escape_path(path))
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
79
78
|
def create_dir(path)
|
80
79
|
log.info "Creating #{path}"
|
81
|
-
run(path) do
|
80
|
+
run(path) do
|
82
81
|
case res = @client.file_create_folder(@conf["root"], path)
|
83
82
|
when Net::HTTPForbidden
|
84
|
-
raise RemoteAlreadyExists, "
|
83
|
+
raise RemoteAlreadyExists, "Either the directory at #{path} already exists, or it has invalid characters in the name"
|
85
84
|
else
|
86
85
|
res
|
87
86
|
end
|
@@ -90,38 +89,37 @@ module Dbox
|
|
90
89
|
|
91
90
|
def delete_dir(path)
|
92
91
|
log.info "Deleting #{path}"
|
93
|
-
run(path) do
|
92
|
+
run(path) do
|
94
93
|
@client.file_delete(@conf["root"], path)
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
98
97
|
def get_file(path)
|
99
98
|
log.info "Downloading #{path}"
|
100
|
-
run(path) do
|
101
|
-
@client.get_file(@conf["root"], path)
|
99
|
+
run(path) do
|
100
|
+
@client.get_file(@conf["root"], escape_path(path))
|
102
101
|
end
|
103
102
|
end
|
104
103
|
|
105
104
|
def put_file(path, file_obj)
|
106
105
|
log.info "Uploading #{path}"
|
107
|
-
run(path) do
|
106
|
+
run(path) do
|
108
107
|
dir = File.dirname(path)
|
109
108
|
name = File.basename(path)
|
110
|
-
@client.put_file(@conf["root"], dir, name, file_obj)
|
109
|
+
@client.put_file(@conf["root"], escape_path(dir), name, file_obj)
|
111
110
|
end
|
112
111
|
end
|
113
112
|
|
114
113
|
def delete_file(path)
|
115
114
|
log.info "Deleting #{path}"
|
116
|
-
run(path) do
|
115
|
+
run(path) do
|
117
116
|
@client.file_delete(@conf["root"], path)
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
121
120
|
def move(old_path, new_path)
|
122
121
|
log.info "Moving #{old_path} to #{new_path}"
|
123
|
-
run(old_path) do
|
124
|
-
new_path = escape_path(new_path)
|
122
|
+
run(old_path) do
|
125
123
|
case res = @client.file_move(@conf["root"], old_path, new_path)
|
126
124
|
when Net::HTTPBadRequest
|
127
125
|
raise RemoteAlreadyExists, "Error during move -- there may already be a Dropbox folder at #{new_path}"
|
@@ -132,7 +130,7 @@ module Dbox
|
|
132
130
|
end
|
133
131
|
|
134
132
|
def escape_path(path)
|
135
|
-
|
133
|
+
path.split("/").map {|s| CGI.escape(s).gsub("+", "%20") }.join("/")
|
136
134
|
end
|
137
135
|
|
138
136
|
def self.conf
|
data/lib/dbox/db.rb
CHANGED
@@ -322,9 +322,10 @@ module Dbox
|
|
322
322
|
}
|
323
323
|
|
324
324
|
if attrs["is_dir"] && list_contents
|
325
|
-
contents = Dir
|
326
|
-
attrs["contents"] = contents.map do |
|
327
|
-
|
325
|
+
contents = Dir.entries(full).reject {|s| s == "." || s == ".." }
|
326
|
+
attrs["contents"] = contents.map do |s|
|
327
|
+
p = File.join(full, s)
|
328
|
+
r = @db.local_to_relative_path(p)
|
328
329
|
gather_info(r, false)
|
329
330
|
end
|
330
331
|
end
|
data/spec/dbox_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2
4
|
|
3
5
|
include FileUtils
|
@@ -181,6 +183,27 @@ describe Dbox do
|
|
181
183
|
Dbox.push(@local).should eql(:created => ["subdir", "subdir/one.txt"], :deleted => ["foo.txt"], :updated => ["baz.txt"])
|
182
184
|
Dbox.pull(@local).should eql(:created => [], :deleted => [], :updated => [])
|
183
185
|
end
|
186
|
+
|
187
|
+
it "should be able to handle crazy filenames" do
|
188
|
+
Dbox.create(@remote, @local)
|
189
|
+
crazy_name1 = '=+!@# $%^&*()[]{}<>_-|:?,\'~".txt'
|
190
|
+
crazy_name2 = '[ˈdɔʏtʃ].txt'
|
191
|
+
touch "#{@local}/#{crazy_name1}"
|
192
|
+
touch "#{@local}/#{crazy_name2}"
|
193
|
+
Dbox.push(@local).should eql(:created => [crazy_name1, crazy_name2], :deleted => [], :updated => [])
|
194
|
+
rm_rf @local
|
195
|
+
Dbox.clone(@remote, @local).should eql(:created => [crazy_name1, crazy_name2], :deleted => [], :updated => [])
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should be able to handle directory names" do
|
199
|
+
Dbox.create(@remote, @local)
|
200
|
+
crazy_name1 = "Day[J] #42"
|
201
|
+
mkdir File.join(@local, crazy_name1)
|
202
|
+
touch File.join(@local, crazy_name1, "foo.txt")
|
203
|
+
Dbox.push(@local).should eql(:created => [crazy_name1, File.join(crazy_name1, "foo.txt")], :deleted => [], :updated => [])
|
204
|
+
rm_rf @local
|
205
|
+
Dbox.clone(@remote, @local).should eql(:created => [crazy_name1, File.join(crazy_name1, "foo.txt")], :deleted => [], :updated => [])
|
206
|
+
end
|
184
207
|
end
|
185
208
|
|
186
209
|
describe "#move" do
|
metadata
CHANGED