sys-filesystem 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGE1OWI0MWYwNTQ0OTFmNWZlMWVjOWZjYzVlNjkwNjFjYmU5MzdkOQ==
5
- data.tar.gz: !binary |-
6
- MDU1NzgzNDY5YjEyODA5NWI1NDBhZGE1YjVmYTk4MDEzOGYwOGM5YQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NzQ1NmJhMThiZDY0YTg0NDJjOTFkNGNlNzMxYWU4YjI5MmNhOTQ5ZjQ1N2Iy
10
- MjQ3NmZmNTllZDkzODk2YmZlYWZmYjA5YWNmNTMxOGZhOWJmOWZlZDUxNzcx
11
- N2Q2YmM2NWM1YTBjNzFiOGY0ZTlmYzczNTI1ODNmNzU0ODk3ZjQ=
12
- data.tar.gz: !binary |-
13
- ZGQ0ZWIzNTc3MWQwZmQwMGNhYzJiNjdiNjU3MDk0MjYxZWI3NzcxZjI0NGM0
14
- MGE3MTUzOTVmOTlkYzg3MmQxMTk0MTMxMmZlYzI1MDA3ZTA5N2EyMzNmOTk4
15
- NTJkZGRhNThhZTJiNGY1ZjA4ZWQwYTVmNGUxOWViZmQ3ZWFkZmQ=
2
+ SHA1:
3
+ metadata.gz: 34f3ac9a042ae4f81d584a6c32aec6bd0365c12c
4
+ data.tar.gz: a5fa1fd3b884a0e10249fd7583ed64536d4448cc
5
+ SHA512:
6
+ metadata.gz: bf773f2a53550dfac708332522396932f9830d0721476d8d6abaee17ed11f70d919f4b0b9bdc058a1214678138b74a660712f59b982deb10dbf8f1f69d9de4be
7
+ data.tar.gz: 3defee7ad40391abe85802270fb353a036190df7ed8ed1828c357cb2804344f1d4c8e31bbf1e0b04d90bfc60106ba2a5d69ba9ba64924619569a0c738490683d
data/CHANGES CHANGED
@@ -1,3 +1,12 @@
1
+ == 1.1.2 - 9-May-2014
2
+ * Added the percent_used, bytes_total, bytes_free and bytes_used methods
3
+ to the Filesystem::Stat class. Thanks go to xanview for the suggestion.
4
+ * Changed File.exists? to File.exist? to avoid warnings in Ruby 2.1.x.
5
+ * The convenience methods to_mb, to_gb, etc, are now defined in Numeric
6
+ instead of Fixnum.
7
+ * Added the to_tb method for terabytes.
8
+ * Minor updates to the gem:create and gem:install Rake tasks.
9
+
1
10
  == 1.1.1 - 3-Oct-2013
2
11
  * Solaris now always uses statvfs64 on Solaris for better 64-bit support.
3
12
  Thanks go to Jeff Shantz for the spot.
data/README CHANGED
@@ -44,7 +44,7 @@
44
44
  is 'example_stat.rb' in the 'examples' directory. Modify it as you see fit.
45
45
 
46
46
  = Known Bugs
47
- None that I'm aware of. Please report bugs on the project page at
47
+ None that I'm aware of. Please report bugs on the project page at
48
48
  https://github.com/djberg96/sys-filesystem
49
49
 
50
50
  = Future Plans
@@ -52,8 +52,7 @@
52
52
  Other suggestions welcome.
53
53
 
54
54
  = Acknowledgements
55
- Mike Hall, for ideas and code that I borrowed from his 'filesystem'
56
- library.
55
+ Mike Hall, for ideas and code that I borrowed from his 'filesystem' library.
57
56
 
58
57
  Park Heesob, for implementation and API ideas for the MS Windows version.
59
58
 
@@ -69,7 +68,7 @@
69
68
  http://www.gittip.com/djberg96/
70
69
 
71
70
  = Copyright
72
- (C) 2003-2013 Daniel J. Berger
71
+ (C) 2003-2014 Daniel J. Berger
73
72
  All Rights Reserved
74
73
 
75
74
  = Warranty
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  namespace :gem do
26
26
  desc "Build the sys-filesystem gem"
27
- task :create do |t|
27
+ task :create => [:clean] do |t|
28
28
  spec = eval(IO.read('sys-filesystem.gemspec'))
29
29
  if Gem::VERSION >= "2.0.0"
30
30
  require 'rubygems/package'
@@ -37,7 +37,7 @@ namespace :gem do
37
37
  desc "Install the sys-filesystem gem"
38
38
  task :install => [:create] do
39
39
  file = Dir['*.gem'].first
40
- sh "gem install #{file}"
40
+ sh "gem install -l #{file}"
41
41
  end
42
42
  end
43
43
 
@@ -10,7 +10,7 @@ module Sys
10
10
  ffi_lib FFI::Library::LIBC
11
11
 
12
12
  # The version of the sys-filesystem library.
13
- VERSION = '1.1.1'
13
+ VERSION = '1.1.2'
14
14
 
15
15
  private
16
16
 
@@ -103,9 +103,9 @@ module Sys
103
103
  }
104
104
 
105
105
  # File used to read mount informtion from.
106
- if File.exists?('/etc/mtab')
106
+ if File.exist?('/etc/mtab')
107
107
  MOUNT_FILE = '/etc/mtab'
108
- elsif File.exists?('/etc/mnttab')
108
+ elsif File.exist?('/etc/mnttab')
109
109
  MOUNT_FILE = '/etc/mnttab'
110
110
  else
111
111
  MOUNT_FILE = 'getmntinfo'
@@ -326,6 +326,26 @@ module Sys
326
326
  @name_max = nil
327
327
  @base_type = nil
328
328
  end
329
+
330
+ # Returns the total space on the partition.
331
+ def bytes_total
332
+ blocks * block_size
333
+ end
334
+
335
+ # Returns the total amount of free space on the partition.
336
+ def bytes_free
337
+ blocks_available * block_size
338
+ end
339
+
340
+ # Returns the total amount of used space on the partition.
341
+ def bytes_used
342
+ bytes_total - bytes_free
343
+ end
344
+
345
+ # Returns the percentage of the partition that has been used.
346
+ def percent_used
347
+ 100 - (100.0 * bytes_free.to_f / bytes_total.to_f)
348
+ end
329
349
  end
330
350
 
331
351
  # Mount objects are returned by the Sys::Filesystem.mounts method.
@@ -548,7 +568,7 @@ module Sys
548
568
  end
549
569
  end
550
570
 
551
- class Fixnum
571
+ class Numeric
552
572
  # Converts a number to kilobytes.
553
573
  def to_kb
554
574
  self / 1024
@@ -563,4 +583,9 @@ class Fixnum
563
583
  def to_gb
564
584
  self / 1073741824
565
585
  end
586
+
587
+ # Converts a number to terabytes.
588
+ def to_tb
589
+ self / 1099511627776
590
+ end
566
591
  end
@@ -19,7 +19,7 @@ module Sys
19
19
  class Error < StandardError; end
20
20
 
21
21
  # The version of the sys-filesystem library.
22
- VERSION = '1.1.1'
22
+ VERSION = '1.1.2'
23
23
 
24
24
  class Mount
25
25
  # The name of the volume. This is the device mapping.
@@ -55,7 +55,7 @@ module Sys
55
55
  # The path of the file system.
56
56
  attr_reader :path
57
57
 
58
- # The file system block size. MS Windows typically defaults to 4096.
58
+ # The file system block size. MS Windows typically defaults to 4096.
59
59
  attr_reader :block_size
60
60
 
61
61
  # Fragment size. Meaningless at the moment.
@@ -77,7 +77,7 @@ module Sys
77
77
  attr_reader :files
78
78
 
79
79
  # Total number of free files/inodes that can be created on the file
80
- # system. This attribute is always nil on MS Windows.
80
+ # system. This attribute is always nil on MS Windows.
81
81
  attr_reader :files_free
82
82
 
83
83
  # Total number of available files/inodes for unprivileged processes
@@ -97,9 +97,27 @@ module Sys
97
97
  # The file system type, e.g. NTFS, FAT, etc.
98
98
  attr_reader :base_type
99
99
 
100
+ # Returns the total amount of free space on the partition.
101
+ attr_reader :bytes_free
102
+
100
103
  alias inodes files
101
104
  alias inodes_free files_free
102
105
  alias inodes_available files_available
106
+
107
+ # Returns the total space on the partition.
108
+ def bytes_total
109
+ blocks * block_size
110
+ end
111
+
112
+ # Returns the total amount of used space on the partition.
113
+ def bytes_used
114
+ bytes_total - bytes_free
115
+ end
116
+
117
+ # Returns the percentage of the partition that has been used.
118
+ def percent_used
119
+ 100 - (100.0 * bytes_free.to_f / bytes_total.to_f)
120
+ end
103
121
  end
104
122
 
105
123
  # Yields a Filesystem::Mount object for each volume on your system in
@@ -313,6 +331,7 @@ module Sys
313
331
  stat_obj.instance_variable_set(:@base_type, base_type)
314
332
  stat_obj.instance_variable_set(:@flags, flags)
315
333
  stat_obj.instance_variable_set(:@filesystem_id, vol_serial)
334
+ stat_obj.instance_variable_set(:@bytes_free, bytes_free)
316
335
 
317
336
  stat_obj.freeze # Read-only object
318
337
  end
@@ -367,28 +386,36 @@ end
367
386
 
368
387
  # Some convenient methods for converting bytes to kb, mb, and gb.
369
388
  #
370
- class Fixnum
389
+ class Numeric
371
390
  # call-seq:
372
- # <tt>fix</tt>.to_kb
391
+ # <tt>num</tt>.to_kb
373
392
  #
374
- # Returns +fix+ in terms of kilobytes.
393
+ # Returns +num+ in terms of kilobytes.
375
394
  def to_kb
376
395
  self / 1024
377
396
  end
378
397
 
379
398
  # call-seq:
380
- # <tt>fix</tt>.to_mb
399
+ # <tt>num</tt>.to_mb
381
400
  #
382
- # Returns +fix+ in terms of megabytes.
401
+ # Returns +num+ in terms of megabytes.
383
402
  def to_mb
384
403
  self / 1048576
385
404
  end
386
405
 
387
406
  # call-seq:
388
- # <tt>fix</tt>.to_gb
407
+ # <tt>num</tt>.to_gb
389
408
  #
390
- # Returns +fix+ in terms of gigabytes.
409
+ # Returns +num+ in terms of gigabytes.
391
410
  def to_gb
392
411
  self / 1073741824
393
412
  end
413
+
414
+ # call-seq:
415
+ # <tt>num</tt>.to_gb
416
+ #
417
+ # Returns +num+ in terms of terabytes.
418
+ def to_tb
419
+ self / 1099511627776
420
+ end
394
421
  end
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sys-filesystem'
5
- spec.version = '1.1.1'
5
+ spec.version = '1.1.2'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.email = 'djberg96@gmail.com'
8
8
  spec.homepage = 'https://github.com/djberg96/sys-filesystem'
@@ -25,7 +25,7 @@ class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def test_version
28
- assert_equal('1.1.1', Filesystem::VERSION)
28
+ assert_equal('1.1.2', Filesystem::VERSION)
29
29
  end
30
30
 
31
31
  def test_stat_path
@@ -124,14 +124,35 @@ class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
124
124
  assert_not_nil(Filesystem::Stat::NOTRUNC)
125
125
  end
126
126
 
127
+ def test_stat_bytes_total
128
+ assert_respond_to(@stat, :bytes_total)
129
+ assert_kind_of(Numeric, @stat.bytes_total)
130
+ end
131
+
132
+ def test_stat_bytes_free
133
+ assert_respond_to(@stat, :bytes_free)
134
+ assert_kind_of(Numeric, @stat.bytes_free)
135
+ end
136
+
137
+ def test_stat_bytes_used
138
+ assert_respond_to(@stat, :bytes_used)
139
+ assert_kind_of(Numeric, @stat.bytes_used)
140
+ end
141
+
142
+ def test_stat_percent_used
143
+ assert_respond_to(@stat, :percent_used)
144
+ assert_kind_of(Float, @stat.percent_used)
145
+ end
146
+
127
147
  def test_stat_expected_errors
128
148
  assert_raises(ArgumentError){ Filesystem.stat }
129
149
  end
130
150
 
131
- def test_fixnum_methods_basic
151
+ def test_numeric_methods_basic
132
152
  assert_respond_to(@size, :to_kb)
133
153
  assert_respond_to(@size, :to_mb)
134
154
  assert_respond_to(@size, :to_gb)
155
+ assert_respond_to(@size, :to_tb)
135
156
  end
136
157
 
137
158
  def test_to_kb
@@ -19,7 +19,7 @@ class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  test "version number is set to the expected value" do
22
- assert_equal('1.1.1', Filesystem::VERSION)
22
+ assert_equal('1.1.2', Filesystem::VERSION)
23
23
  end
24
24
 
25
25
  test "stat path works as expected" do
@@ -99,6 +99,26 @@ class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
99
99
  assert_kind_of(String, @stat.base_type)
100
100
  end
101
101
 
102
+ test "stat bytes_total basic functionality" do
103
+ assert_respond_to(@stat, :bytes_total)
104
+ assert_kind_of(Numeric, @stat.bytes_total)
105
+ end
106
+
107
+ test "stat bytes_free basic functionality" do
108
+ assert_respond_to(@stat, :bytes_free)
109
+ assert_kind_of(Numeric, @stat.bytes_free)
110
+ end
111
+
112
+ test "stat bytes_used basic functionality" do
113
+ assert_respond_to(@stat, :bytes_used)
114
+ assert_kind_of(Numeric, @stat.bytes_used)
115
+ end
116
+
117
+ test "stat percent_used basic functionality" do
118
+ assert_respond_to(@stat, :percent_used)
119
+ assert_kind_of(Float, @stat.percent_used)
120
+ end
121
+
102
122
  test "mount_point singleton method basic functionality" do
103
123
  assert_respond_to(Filesystem, :mount_point)
104
124
  assert_nothing_raised{ Filesystem.mount_point(Dir.pwd) }
metadata CHANGED
@@ -1,59 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-filesystem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-04 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.5.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.5.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: ! " The sys-filesystem library provides an interface for gathering
56
- filesystem\n information, such as disk space and mount point data.\n"
55
+ description: |2
56
+ The sys-filesystem library provides an interface for gathering filesystem
57
+ information, such as disk space and mount point data.
57
58
  email: djberg96@gmail.com
58
59
  executables: []
59
60
  extensions: []
@@ -63,17 +64,17 @@ extra_rdoc_files:
63
64
  - MANIFEST
64
65
  files:
65
66
  - CHANGES
67
+ - MANIFEST
68
+ - README
69
+ - Rakefile
66
70
  - examples/example_stat.rb
67
71
  - lib/sys/filesystem.rb
68
72
  - lib/unix/sys/filesystem.rb
73
+ - lib/windows/sys/filesystem.rb
69
74
  - lib/windows/sys/filesystem/constants.rb
70
75
  - lib/windows/sys/filesystem/functions.rb
71
76
  - lib/windows/sys/filesystem/helper.rb
72
77
  - lib/windows/sys/filesystem/structs.rb
73
- - lib/windows/sys/filesystem.rb
74
- - MANIFEST
75
- - Rakefile
76
- - README
77
78
  - sys-filesystem.gemspec
78
79
  - test/test_sys_filesystem.rb
79
80
  - test/test_sys_filesystem_unix.rb
@@ -88,17 +89,17 @@ require_paths:
88
89
  - lib
89
90
  required_ruby_version: !ruby/object:Gem::Requirement
90
91
  requirements:
91
- - - ! '>='
92
+ - - ">="
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  requirements:
96
- - - ! '>='
97
+ - - ">="
97
98
  - !ruby/object:Gem::Version
98
99
  version: '0'
99
100
  requirements: []
100
101
  rubyforge_project: sysutils
101
- rubygems_version: 2.0.3
102
+ rubygems_version: 2.2.2
102
103
  signing_key:
103
104
  specification_version: 4
104
105
  summary: A Ruby interface for getting file system information.