decimate 0.0.2 → 0.0.4
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/README.md +7 -2
- data/lib/decimate.rb +16 -11
- data/lib/decimate/version.rb +1 -1
- data/spec/lib/decimate_spec.rb +4 -4
- metadata +1 -1
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Decimate
|
2
2
|
|
3
|
-
[](http://travis-ci.org/justinwiley/decimate)
|
4
4
|
|
5
5
|
Discipline your file system by securely deleting some of its precious files or directories using shred.
|
6
6
|
|
7
|
-
### Notable features
|
7
|
+
### Notable features
|
8
8
|
|
9
9
|
- Uses shred utility to securely delete files, before removing
|
10
10
|
- Allows additional sanity checking of paths
|
@@ -43,6 +43,11 @@ See RDoc for details.
|
|
43
43
|
|
44
44
|
Code reviews, comments, violent reactions welcome.
|
45
45
|
|
46
|
+
Thanks to tokland for suggestions.
|
47
|
+
|
48
|
+
http://codereview.stackexchange.com/questions/28265/securely-deleting-files-while-attempting-to-protect-the-user-against-obviously
|
49
|
+
|
50
|
+
|
46
51
|
### Installation
|
47
52
|
|
48
53
|
Add this line to your application's Gemfile:
|
data/lib/decimate.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "decimate/version"
|
2
|
+
require 'shellwords'
|
2
3
|
require 'fileutils'
|
3
4
|
require 'open3'
|
4
5
|
|
@@ -10,15 +11,21 @@ module Decimate
|
|
10
11
|
#
|
11
12
|
def self.run cmd
|
12
13
|
stdout,stderr,status = Open3.capture3 cmd
|
13
|
-
raise "
|
14
|
+
raise "Failed executing #{cmd}: stdout: #{stdout}, stderr: #{stderr}, status #{status}" unless status.nil? || status == 0
|
14
15
|
stdout
|
15
16
|
end
|
16
17
|
|
18
|
+
# Check for shred, escape path, ensure path isn't root dir or fails regexp
|
19
|
+
def self.validate path, required_regex=nil
|
20
|
+
fail_unless_shred
|
21
|
+
escaped_path = Shellwords.escape path
|
22
|
+
validate_path escaped_path, required_regex
|
23
|
+
end
|
24
|
+
|
17
25
|
def self.validate_path path, required_regex=nil
|
18
|
-
raise ArgumentError.new("expected Regexp, given #{required_regex.class}") if required_regex && !required_regex.is_a?(Regexp)
|
19
26
|
File.expand_path(path).tap do |path|
|
20
|
-
raise
|
21
|
-
raise
|
27
|
+
raise "Trying to remove root dir? Path: #{path}" if path == '/'
|
28
|
+
raise "Path #{path} does not match #{required_regex}" if required_regex && !path.match(required_regex)
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
@@ -37,9 +44,8 @@ module Decimate
|
|
37
44
|
#
|
38
45
|
def self.file! path, opts={}
|
39
46
|
return unless File.exist?(path)
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
path = validate path, opts[:path_must_match]
|
48
|
+
|
43
49
|
run "#{shred_cmd} #{path}"
|
44
50
|
end
|
45
51
|
|
@@ -58,10 +64,9 @@ module Decimate
|
|
58
64
|
#
|
59
65
|
def self.dir! path, opts={}
|
60
66
|
return unless Dir.exist?(path)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
stdout = run "find #{path} -type f -exec #{shred_cmd} '{}' ';'"
|
67
|
+
path = validate path, opts[:path_must_match]
|
68
|
+
|
69
|
+
stdout = run "find #{path} -type f -exec #{shred_cmd} {} +"
|
65
70
|
FileUtils.rm_rf path
|
66
71
|
stdout
|
67
72
|
end
|
data/lib/decimate/version.rb
CHANGED
data/spec/lib/decimate_spec.rb
CHANGED
@@ -28,8 +28,8 @@ describe Decimate do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should raise if expanded path matches /' do
|
31
|
-
expect{Decimate.validate_path('/')}.to raise_error
|
32
|
-
expect{Decimate.validate_path('/dir/../')}.to raise_error
|
31
|
+
expect{Decimate.validate_path('/')}.to raise_error
|
32
|
+
expect{Decimate.validate_path('/dir/../')}.to raise_error
|
33
33
|
end
|
34
34
|
context 'with required path match argument' do
|
35
35
|
it 'should return path if expanded path matches given' do
|
@@ -37,7 +37,7 @@ describe Decimate do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should raise if not' do
|
40
|
-
expect{Decimate.validate_path(file, /another_dir/)}.to raise_error
|
40
|
+
expect{Decimate.validate_path(file, /another_dir/)}.to raise_error
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -84,7 +84,7 @@ describe Decimate do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should securely delete all files under the given file' do
|
87
|
-
Open3.should_receive(:capture3).with("find #{dir} -type f -exec shred -uv
|
87
|
+
Open3.should_receive(:capture3).with("find #{dir} -type f -exec shred -uv {} +")
|
88
88
|
Decimate.dir! dir
|
89
89
|
end
|
90
90
|
|