awscli 0.0.5 → 0.0.6
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.
- checksums.yaml +8 -8
- data/lib/awscli.rb +1 -1
- data/lib/awscli/cli/s3/directories.rb +7 -0
- data/lib/awscli/s3.rb +65 -0
- data/lib/awscli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjlmNjJhN2FmMDg3MTE5ZWEyNmQwZDI1MjQ2MTBkY2Y5MWIxNjQyYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDk3MDBiZmQ5ODZjMzI2Y2NkNGM0ZmFlMTEyYmM2N2U5NjkwMzAxMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2ZlYmY2NjI4MGFhNjZjOWYzNDFjMjMxMTJjMGNlMmViMDgyNDEzOTJlYzE4
|
10
|
+
YzI2MmJhNGNjOGI1Yzg0YzFkZTM1ZjI0NjY1MjBkMDRlNGQ5MTdiYmViNjM4
|
11
|
+
NGNhMjZjN2IyMGY4MDg4ZDI3NzJjMGM3NTM5NWM1MzllYTJlOTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWMxZjRkNDBhNDg4OTUyOTdkYTQ5YTE5MmNhZjg3NWM0NDNmNGE5OWY5YmFi
|
14
|
+
ODEwOWViMDBmM2QxMjc2YjdmMDYxZWI5M2Y0Y2VkMjkxYTU0MGUzOGY5MjU3
|
15
|
+
NzM5MWRkZmFiZDFiNTQ0M2RmYmEwNDE2MThhYWZiM2JkMjA5NDg=
|
data/lib/awscli.rb
CHANGED
@@ -26,6 +26,13 @@ module AwsCli
|
|
26
26
|
@s3.delete options[:key]
|
27
27
|
end
|
28
28
|
|
29
|
+
desc "delete_rec", "Delete the bucket and all its contents"
|
30
|
+
method_option :key, :aliases => "-k", :type => :string, :required => true, :desc => "name of the bucket to delete"
|
31
|
+
def delete_rec
|
32
|
+
create_s3_object
|
33
|
+
@s3.delete_rec options[:key]
|
34
|
+
end
|
35
|
+
|
29
36
|
desc "set_acl", "Change access control list for an S3 bucket"
|
30
37
|
method_option :key, :aliases => "-k", :type => :string, :required => true, :desc => "name of the bucket to change acl"
|
31
38
|
method_option :acl, :aliases => "-a", :type => :string, :required => true, :desc => "Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']"
|
data/lib/awscli/s3.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Awscli
|
2
2
|
module S3
|
3
|
+
require 'thread'
|
3
4
|
|
4
5
|
class Files
|
5
6
|
def initialize connection, options = {}
|
@@ -78,10 +79,74 @@ module Awscli
|
|
78
79
|
def delete dir_name
|
79
80
|
dir = @@conn.directories.get(dir_name)
|
80
81
|
abort "Cannot find bucket #{dir_name}" unless dir
|
82
|
+
#check if the dir is empty or not
|
83
|
+
abort "Bucket is not empty, use rec_delete to force delete bucket" if dir.files.length != 0
|
81
84
|
dir.destroy
|
82
85
|
puts "Deleted Bucket: #{dir_name}"
|
83
86
|
end
|
84
87
|
|
88
|
+
def delete_rec dir_name
|
89
|
+
#Forked from https://gist.github.com/bdunagan/1383301
|
90
|
+
data_queue = Queue.new
|
91
|
+
semaphore = Mutex.new
|
92
|
+
threads = Array.new
|
93
|
+
total_listed = 0
|
94
|
+
total_deleted = 0
|
95
|
+
thread_count = 20 #num_of_threads to perform deletion
|
96
|
+
dir = @@conn.directories.get(dir_name)
|
97
|
+
abort "Cannot find bucket #{dir_name}" unless dir
|
98
|
+
if dir.files.length != 0
|
99
|
+
if agree("Are you sure want to delete all the objects in the bucket ? ", true)
|
100
|
+
puts
|
101
|
+
puts "==Deleting all the files in '#{dir_name}'=="
|
102
|
+
#fetch files in the bucket
|
103
|
+
threads << Thread.new do
|
104
|
+
Thread.current[:name] = "get files"
|
105
|
+
puts "...started thread '#{Thread.current[:name]}'...\n"
|
106
|
+
# Get all the files from this bucket. Fog handles pagination internally
|
107
|
+
dir.files.all.each do |file|
|
108
|
+
data_queue.enq(file) #add the file into the queue
|
109
|
+
total_listed += 1
|
110
|
+
end
|
111
|
+
# Add a final EOF message to signal the deletion threads to stop.
|
112
|
+
thread_count.times {data_queue.enq(:EOF)}
|
113
|
+
end
|
114
|
+
# Delete all the files in the queue until EOF with N threads.
|
115
|
+
thread_count.times do |count|
|
116
|
+
threads << Thread.new(count) do |number|
|
117
|
+
Thread.current[:name] = "delete files(#{number})"
|
118
|
+
puts "...started thread '#{Thread.current[:name]}'...\n"
|
119
|
+
# Dequeue until EOF.
|
120
|
+
file = nil
|
121
|
+
while file != :EOF
|
122
|
+
# Dequeue the latest file and delete it. (Will block until it gets a new file.)
|
123
|
+
file = data_queue.deq
|
124
|
+
file.destroy if file != :EOF
|
125
|
+
# Increment the global synchronized counter.
|
126
|
+
semaphore.synchronize {total_deleted += 1}
|
127
|
+
puts "Deleted #{total_deleted} out of #{total_listed}\n" if (rand(100) == 1)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
# Wait for the threads to finish.
|
132
|
+
threads.each do |t|
|
133
|
+
begin
|
134
|
+
t.join
|
135
|
+
rescue RuntimeError => e
|
136
|
+
puts "Failure on thread #{t[:name]}: #{e.message}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
#finally delete the bucket it self
|
140
|
+
dir.destroy
|
141
|
+
puts "Deleted bucket: #{dir_name} and all its contents"
|
142
|
+
end
|
143
|
+
else
|
144
|
+
#empty bucket
|
145
|
+
dir.destroy
|
146
|
+
puts "Deleted bucket: #{dir_name}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
85
150
|
def get_acl dir_name
|
86
151
|
dir = @@conn.directories.get(dir_name)
|
87
152
|
abort "Cannot find bucket #{dir_name}" unless dir
|
data/lib/awscli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awscli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashrith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|