file_discard 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d198ac94a7993ffcc15a2d4985561d1bee2b94d0
4
- data.tar.gz: d2d4305716fc3c960a967c3d10fef7c665faaf63
3
+ metadata.gz: c7539efaa26ed718413f4770434de5cb04a45d36
4
+ data.tar.gz: 514b8d987d89790aa7aac1585b878b189afdf6a4
5
5
  SHA512:
6
- metadata.gz: 215102e583870fe1b07e3b14a477ba60e2dff2e29c7a7ca93f105d7f16e5e07b1e06288f69022408e30d410fd8048648f09d66876a6f99c034fd2fef0c2b2aa8
7
- data.tar.gz: dfebe4588ecac6db54049c6193c6f02c56c576a4a02126af40686014a8b7ff8d502768702a5b89c54ccb89356ae370c3c00923333a3415f6f417929f243cab97
6
+ metadata.gz: 6c1e810875af7e912f85055a77c937c679afaaa8ea374815239150ca48aeaef432e9b7974ccb26fcc83b83aa223953de667a9dda91633f94f039fd14f088a6e1
7
+ data.tar.gz: 5ac9cd626b81ef753135565cf3ace8865f1dea0c5d82bdb11be5aa5edd2eaefe038c211441f9aa46d52654051ff9b919440df8cca3a83e3f26823537c2b0c3b6
data/README.md CHANGED
@@ -2,6 +2,14 @@ FileDiscard is a simple helper to make it easy for applications to move files to
2
2
 
3
3
  ## Getting Started
4
4
 
5
+ ### Installation
6
+
7
+ ```shell
8
+ > gem install file_discard
9
+ ```
10
+
11
+ [![Gem Version](https://badge.fury.io/rb/file_discard.svg)](http://badge.fury.io/rb/file_discard)
12
+
5
13
  ### Using the Executable
6
14
 
7
15
  Part of the `file_discard` gem is an executable that can be used as a drop-in replacement for "rm":
@@ -9,6 +17,7 @@ Part of the `file_discard` gem is an executable that can be used as a drop-in re
9
17
  ```shell
10
18
  > discard
11
19
  Usage: discard [options] file ...
20
+ -f, --force when provided twice, permanently remove targets
12
21
  -d, --dir allow empty directories to be discarded
13
22
  -r allow directories to be discarded recursively
14
23
  -R, --recursive allow directories to be discarded recursively
@@ -17,7 +26,6 @@ Usage: discard [options] file ...
17
26
  --version show version
18
27
 
19
28
  Options ignored to provide compatibility with "rm":
20
- -f
21
29
  -i
22
30
  -I
23
31
  ```
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ task default: :test
8
8
  task spec: :test
9
9
  task build: :package
10
10
 
11
- PKG_VERSION = '0.1.5'
11
+ PKG_VERSION = '0.1.6'
12
12
  NOW = Time.now.utc
13
13
 
14
14
  # delay updating the version file unless building the gem or package
data/bin/discard CHANGED
@@ -55,8 +55,14 @@ FileDiscard.create_trash_when_missing = true
55
55
 
56
56
  status = 0
57
57
  ARGV.each do |file|
58
+ options.force > 1 and $stderr.puts "Warning: Permanently removing #{file}"
58
59
  begin
59
60
  FileDiscard.discard(file, options.marshal_dump)
61
+ rescue FileDiscard::TrashNotPermitted => ex
62
+ $stderr.puts "#{parser.program_name}: #{file}: #{ex.message}"
63
+ options.verbose and $stderr.puts ex.backtrace
64
+ $stderr.puts "Consider using -ff to permanently remove"
65
+ status = 3
60
66
  rescue Errno::EINVAL, Errno::ENOENT => ex
61
67
  $stderr.puts "#{parser.program_name}: #{file}: #{ex.message}"
62
68
  status = 1
data/lib/file_discard.rb CHANGED
@@ -85,6 +85,10 @@ module FileDiscard
85
85
  # Raised when the configured trash directory for a given mountpoint does not exist.
86
86
  class TrashMissing < Errno::ENOENT; end;
87
87
 
88
+ # Raised when the configured trash directory for a given mountpoint does not exist
89
+ # and user does not have permissions to create it.
90
+ class TrashNotPermitted < Errno::EACCES; end;
91
+
88
92
  # The core logic for moving files to an appropriate trash directory.
89
93
  class Discarder
90
94
  SPECIAL_DIRS = ['.','..'] # :nodoc:
@@ -99,6 +103,7 @@ module FileDiscard
99
103
  # Request that +obj+ be moved to the trash.
100
104
  #
101
105
  # +options+ - a hash of any of the following:
106
+ # * :force - if greater than one, permanently remove +obj+
102
107
  # * :directory - allow an empty directory to be discarded
103
108
  # * :recursive - allow a directory to be discarded even if not empty
104
109
  # * :verbose - report the move operation
@@ -122,7 +127,6 @@ module FileDiscard
122
127
  end
123
128
 
124
129
  if options.key?(:force) && options[:force] > 1
125
- $stderr.puts "Warning: Permanently removing #{pn}"
126
130
  FileUtils.rm_rf(pn, {verbose: options[:verbose] || false})
127
131
  return
128
132
  end
@@ -130,7 +134,11 @@ module FileDiscard
130
134
  trash = find_trash_for pn
131
135
  unless trash.exist?
132
136
  FileDiscard.create_trash_when_missing or raise TrashMissing.new(trash.to_s)
133
- trash.mkpath
137
+ begin
138
+ trash.mkpath
139
+ rescue Errno::EACCES
140
+ raise TrashNotPermitted.new("Unable to create #{trash.to_s}")
141
+ end
134
142
  end
135
143
 
136
144
  move_options = options.has_key?(:verbose) ? {verbose: options[:verbose]} : {}
@@ -1,6 +1,6 @@
1
1
  module FileDiscard
2
2
  # :nodoc:
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
  # :nodoc:
5
- RELEASE = '4441d85:20141102225117'
5
+ RELEASE = '7e133b5:20141103000654'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_discard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Robel-Forrest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-02 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple helper to move files to the trash folder.
14
14
  email: brad+filediscard@gigglewax.com