dbox 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/dbox.gemspec +9 -7
  3. data/lib/dbox/database.rb +33 -9
  4. metadata +7 -13
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -5,14 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dbox}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Ken Pratt}]
12
- s.date = %q{2011-09-19}
11
+ s.authors = ["Ken Pratt"]
12
+ s.date = %q{2011-10-03}
13
+ s.default_executable = %q{dbox}
13
14
  s.description = %q{An easy-to-use Dropbox client with fine-grained control over syncs.}
14
15
  s.email = %q{ken@kenpratt.net}
15
- s.executables = [%q{dbox}]
16
+ s.executables = ["dbox"]
16
17
  s.extra_rdoc_files = [
17
18
  "LICENSE.txt",
18
19
  "README.md"
@@ -47,12 +48,13 @@ Gem::Specification.new do |s|
47
48
  "vendor/dropbox-client-ruby/test/util.rb"
48
49
  ]
49
50
  s.homepage = %q{http://github.com/kenpratt/dbox}
50
- s.licenses = [%q{MIT}]
51
- s.require_paths = [%q{lib}]
52
- s.rubygems_version = %q{1.8.5}
51
+ s.licenses = ["MIT"]
52
+ s.require_paths = ["lib"]
53
+ s.rubygems_version = %q{1.3.7}
53
54
  s.summary = %q{Dropbox made easy.}
54
55
 
55
56
  if s.respond_to? :specification_version then
57
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
58
  s.specification_version = 3
57
59
 
58
60
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -11,7 +11,8 @@ module Dbox
11
11
  if db.bootstrapped?
12
12
  raise DatabaseError, "Database already initialized -- please use 'dbox pull' or 'dbox push'."
13
13
  end
14
- db.bootstrap(remote_path, local_path)
14
+ db.bootstrap(remote_path)
15
+ db.migrate()
15
16
  db
16
17
  end
17
18
 
@@ -20,6 +21,7 @@ module Dbox
20
21
  unless db.bootstrapped?
21
22
  raise DatabaseError, "Database not initialized -- please run 'dbox create' or 'dbox clone'."
22
23
  end
24
+ db.migrate()
23
25
  db
24
26
  end
25
27
 
@@ -33,10 +35,13 @@ module Dbox
33
35
  new_db.migrate_entry_from_old_db_format(old_db.root)
34
36
  end
35
37
 
38
+ attr_reader :local_path
39
+
36
40
  # IMPORTANT: Database.new is private. Please use Database.create
37
41
  # or Database.load as the entry point.
38
42
  private_class_method :new
39
43
  def initialize(local_path)
44
+ @local_path = local_path
40
45
  FileUtils.mkdir_p(local_path)
41
46
  @db = SQLite3::Database.new(File.join(local_path, DB_FILENAME))
42
47
  @db.trace {|sql| log.debug sql.strip }
@@ -48,7 +53,6 @@ module Dbox
48
53
  @db.execute_batch(%{
49
54
  CREATE TABLE IF NOT EXISTS metadata (
50
55
  id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
51
- local_path varchar(255) NOT NULL,
52
56
  remote_path varchar(255) NOT NULL,
53
57
  version integer NOT NULL
54
58
  );
@@ -65,13 +69,22 @@ module Dbox
65
69
  })
66
70
  end
67
71
 
68
- METADATA_COLS = [ :local_path, :remote_path, :version ] # don't need to return id
72
+ def migrate
73
+ if metadata[:version] < 2
74
+ @db.execute_batch(%{
75
+ ALTER TABLE metadata DROP COLUMN local_path;
76
+ UPDATE_TABLE metadata SET version = 2;
77
+ })
78
+ end
79
+ end
80
+
81
+ METADATA_COLS = [ :remote_path, :version ] # don't need to return id
69
82
  ENTRY_COLS = [ :id, :path, :is_dir, :parent_id, :hash, :modified, :revision ]
70
83
 
71
- def bootstrap(remote_path, local_path)
84
+ def bootstrap(remote_path)
72
85
  @db.execute(%{
73
- INSERT INTO metadata (local_path, remote_path, version) VALUES (?, ?, ?);
74
- }, local_path, remote_path, 1)
86
+ INSERT INTO metadata (remote_path, version) VALUES (?, ?);
87
+ }, remote_path, 2)
75
88
  @db.execute(%{
76
89
  INSERT INTO entries (path, is_dir) VALUES (?, ?)
77
90
  }, "", 1)
@@ -89,7 +102,9 @@ module Dbox
89
102
  res = @db.get_first_row(%{
90
103
  SELECT #{cols.join(',')} FROM metadata LIMIT 1;
91
104
  })
92
- make_fields(cols, res) if res
105
+ out = { :local_path => local_path }
106
+ out.merge!(make_fields(cols, res)) if res
107
+ out
93
108
  end
94
109
 
95
110
  def update_metadata(fields)
@@ -128,8 +143,17 @@ module Dbox
128
143
  end
129
144
 
130
145
  def delete_entry_by_path(path)
131
- raise(ArgumentError, "path cannot be null") unless path
132
- delete_entry("WHERE path=?", path)
146
+ delete_entry_by_entry(find_by_path(path))
147
+ end
148
+
149
+ def delete_entry_by_entry(entry)
150
+ raise(ArgumentError, "entry cannot be null") unless entry
151
+
152
+ # cascade delete children, if any
153
+ contents(entry[:id]).each {|child| delete_entry_by_entry(child) }
154
+
155
+ # delete main entry
156
+ delete_entry("WHERE id=?", entry[:id])
133
157
  end
134
158
 
135
159
  def migrate_entry_from_old_db_format(entry, parent = nil)
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 5
9
- - 0
10
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Ken Pratt
@@ -15,7 +14,8 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-09-19 00:00:00 Z
17
+ date: 2011-10-03 00:00:00 -07:00
18
+ default_executable: dbox
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: multipart-post
@@ -25,7 +25,6 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 23
29
28
  segments:
30
29
  - 1
31
30
  - 1
@@ -41,7 +40,6 @@ dependencies:
41
40
  requirements:
42
41
  - - ">="
43
42
  - !ruby/object:Gem::Version
44
- hash: 5
45
43
  segments:
46
44
  - 0
47
45
  - 4
@@ -57,7 +55,6 @@ dependencies:
57
55
  requirements:
58
56
  - - ">="
59
57
  - !ruby/object:Gem::Version
60
- hash: 5
61
58
  segments:
62
59
  - 1
63
60
  - 5
@@ -73,7 +70,6 @@ dependencies:
73
70
  requirements:
74
71
  - - ">="
75
72
  - !ruby/object:Gem::Version
76
- hash: 29
77
73
  segments:
78
74
  - 1
79
75
  - 3
@@ -89,7 +85,6 @@ dependencies:
89
85
  requirements:
90
86
  - - ">="
91
87
  - !ruby/object:Gem::Version
92
- hash: 5
93
88
  segments:
94
89
  - 3
95
90
  - 0
@@ -134,6 +129,7 @@ files:
134
129
  - vendor/dropbox-client-ruby/test/authenticator_test.rb
135
130
  - vendor/dropbox-client-ruby/test/client_test.rb
136
131
  - vendor/dropbox-client-ruby/test/util.rb
132
+ has_rdoc: true
137
133
  homepage: http://github.com/kenpratt/dbox
138
134
  licenses:
139
135
  - MIT
@@ -147,7 +143,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
143
  requirements:
148
144
  - - ">="
149
145
  - !ruby/object:Gem::Version
150
- hash: 3
151
146
  segments:
152
147
  - 0
153
148
  version: "0"
@@ -156,14 +151,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
151
  requirements:
157
152
  - - ">="
158
153
  - !ruby/object:Gem::Version
159
- hash: 3
160
154
  segments:
161
155
  - 0
162
156
  version: "0"
163
157
  requirements: []
164
158
 
165
159
  rubyforge_project:
166
- rubygems_version: 1.8.5
160
+ rubygems_version: 1.3.7
167
161
  signing_key:
168
162
  specification_version: 3
169
163
  summary: Dropbox made easy.