liberator 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/dir.rb CHANGED
@@ -7,6 +7,9 @@ class Dir
7
7
  end
8
8
 
9
9
  def self.size(path)
10
- `du -ks "#{path}"`.split("\t").first.to_i*1024 if Dir.exists? path
10
+ if Dir.exists? path
11
+ size = `du -ks "#{path}" 2> /dev/null`
12
+ size.split("\t").first.to_i*1024 if size != ''
13
+ end
11
14
  end
12
15
  end
@@ -27,7 +27,11 @@ module Liberator
27
27
  when 10
28
28
  if File.directory? @directory.selected_entry[:path]
29
29
  @view.update_status_bar "Analyzing #{@directory.selected_entry[:path]}..."
30
- @directory = Directory.new @directory.selected_entry[:path]
30
+ begin
31
+ @directory = Directory.new @directory.selected_entry[:path]
32
+ rescue IOError
33
+ @view.update_status_bar "Cannot change directories due to permissions"
34
+ end
31
35
  render
32
36
  end
33
37
  when 'h'
@@ -23,25 +23,35 @@ module Liberator
23
23
  end
24
24
 
25
25
  def delete_selected_entry
26
- FileUtils.rm_rf selected_entry[:path]
26
+ begin
27
+ FileUtils.rm_r selected_entry[:path]
28
+ rescue Errno::EACCES
29
+ return false
30
+ end
31
+
32
+ true
27
33
  end
28
34
 
29
35
  def refresh
30
- @entries = Dir.real_entries(@path).collect do |entry|
31
- absolute_path = @path + '/' + entry
32
-
33
- if File.file? absolute_path
34
- size = File.size absolute_path
35
- elsif File.directory? absolute_path
36
- size = Dir.size absolute_path
37
- else
38
- next
36
+ begin
37
+ @entries = Dir.real_entries(@path).collect do |entry|
38
+ absolute_path = @path + '/' + entry
39
+
40
+ if File.file? absolute_path
41
+ size = File.size absolute_path
42
+ elsif File.directory? absolute_path
43
+ size = Dir.size absolute_path
44
+ else
45
+ next
46
+ end
47
+
48
+ { path: absolute_path, size: size }
39
49
  end
40
-
41
- { path: absolute_path, size: size }
50
+ @entries = @entries.compact.sort_by { |entry| 1.0/entry[:size].to_f }
51
+ @selected_index = 0
52
+ rescue
53
+ raise IOError.new
42
54
  end
43
- @entries = @entries.compact.sort_by { |entry| 1.0/entry[:size].to_f }
44
- @selected_index = 0
45
55
  end
46
56
  alias_method :cache_entries, :refresh
47
57
  end
@@ -64,6 +64,8 @@ module Liberator
64
64
  end
65
65
 
66
66
  def formatted_size(size)
67
+ return '-' if size.nil?
68
+
67
69
  if size > GIGABYTE
68
70
  "#{size / GIGABYTE} GB"
69
71
  elsif size > MEGABYTE
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liberator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-11 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Liberator helps you find and delete files and directories consuming large
15
15
  amounts of space. It uses a curses interface and is ideally suited for *nix servers