dbox 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dbox}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Ken Pratt}]
@@ -7,6 +7,7 @@ require "fileutils"
7
7
  require "time"
8
8
  require "yaml"
9
9
  require "logger"
10
+ require "cgi"
10
11
 
11
12
  require "dbox/loggable"
12
13
  require "dbox/api"
@@ -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 path
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 |path|
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 |path|
80
+ run(path) do
82
81
  case res = @client.file_create_folder(@conf["root"], path)
83
82
  when Net::HTTPForbidden
84
- raise RemoteAlreadyExists, "The directory at #{path} already exists"
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 |path|
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 |path|
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 |path|
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 |path|
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 |old_path|
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
- URI.escape(path)
133
+ path.split("/").map {|s| CGI.escape(s).gsub("+", "%20") }.join("/")
136
134
  end
137
135
 
138
136
  def self.conf
@@ -322,9 +322,10 @@ module Dbox
322
322
  }
323
323
 
324
324
  if attrs["is_dir"] && list_contents
325
- contents = Dir[File.join(full, "*")]
326
- attrs["contents"] = contents.map do |f|
327
- r = @db.local_to_relative_path(f)
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
@@ -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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Pratt