sys-filesystem 1.1.2 → 1.1.3

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: 34f3ac9a042ae4f81d584a6c32aec6bd0365c12c
4
- data.tar.gz: a5fa1fd3b884a0e10249fd7583ed64536d4448cc
3
+ metadata.gz: c4f18d48f15b2e167689efcba3383011e4d8ee3f
4
+ data.tar.gz: 83007b80b704891feba089e82b7d2d46e1a63ff9
5
5
  SHA512:
6
- metadata.gz: bf773f2a53550dfac708332522396932f9830d0721476d8d6abaee17ed11f70d919f4b0b9bdc058a1214678138b74a660712f59b982deb10dbf8f1f69d9de4be
7
- data.tar.gz: 3defee7ad40391abe85802270fb353a036190df7ed8ed1828c357cb2804344f1d4c8e31bbf1e0b04d90bfc60106ba2a5d69ba9ba64924619569a0c738490683d
6
+ metadata.gz: b7fec893f3575ce639210de2089e8897236af7f84ac48fd8f9db39ed7649491b2792dcd5dc02f62bde79368ee6cfb3bb40f0bc01f52ae8b8c1c2a0cb31ae86f7
7
+ data.tar.gz: 28a988104582d8e4d1c61f3a4f7c3d46a6230ce45e88c2aecdb92aaf1cd05aeb9b5ae95a9f322354991e4f9b9c8c56f7627fa04816d8fcfcaf4598d30e26bb81
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ == 1.1.3 - 1-Oct-2014
2
+ * Now ignores EPERM errors when trying to find the mount point for a path.
3
+ Thanks go to petersen for the patch.
4
+ * The Filesystem.stat method now defaults to using the root path on Windows
5
+ for volume information.
6
+
1
7
  == 1.1.2 - 9-May-2014
2
8
  * Added the percent_used, bytes_total, bytes_free and bytes_used methods
3
9
  to the Filesystem::Stat class. Thanks go to xanview for the suggestion.
@@ -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.2'
13
+ VERSION = '1.1.3'
14
14
 
15
15
  private
16
16
 
@@ -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.2'
22
+ VERSION = '1.1.3'
23
23
 
24
24
  class Mount
25
25
  # The name of the volume. This is the device mapping.
@@ -255,20 +255,23 @@ module Sys
255
255
  end
256
256
 
257
257
  # Returns a Filesystem::Stat object that contains information about the
258
- # +path+ file system.
258
+ # +path+ file system. On Windows this will default to using the root
259
+ # path for volume information.
259
260
  #
260
261
  # Examples:
261
262
  #
262
- # File.stat("C:\\")
263
- # File.stat("C:\\Documents and Settings\\some_user")
263
+ # Sys::Filesystem.stat("C:\\")
264
+ # Sys::Filesystem.stat("C:\\Documents and Settings\\some_user")
264
265
  #
265
266
  def self.stat(path)
266
267
  bytes_avail = FFI::MemoryPointer.new(:ulong_long)
267
268
  bytes_free = FFI::MemoryPointer.new(:ulong_long)
268
269
  total_bytes = FFI::MemoryPointer.new(:ulong_long)
269
270
 
270
- wpath = path.wincode
271
+ mpoint = mount_point(path)
272
+ wpath = path.wincode
271
273
 
274
+ # We need this call for the 64 bit support
272
275
  unless GetDiskFreeSpaceExW(wpath, bytes_avail, total_bytes, bytes_free)
273
276
  raise SystemCallError.new('GetDiskFreeSpaceEx', FFI.errno)
274
277
  end
@@ -282,6 +285,7 @@ module Sys
282
285
  free = FFI::MemoryPointer.new(:ulong_long)
283
286
  total = FFI::MemoryPointer.new(:ulong_long)
284
287
 
288
+ # We need this call for the total/cluster info, which is not in the Ex call.
285
289
  unless GetDiskFreeSpaceW(wpath, sectors, bytes, free, total)
286
290
  raise SystemCallError.new('GetDiskFreeSpace', FFI.errno)
287
291
  end
@@ -295,31 +299,37 @@ module Sys
295
299
  blocks_avail = total_bytes / block_size
296
300
  blocks_free = bytes_free / block_size
297
301
 
298
- vol_name = FFI::MemoryPointer.new(:char, MAXPATH)
299
- base_type = FFI::MemoryPointer.new(:char, MAXPATH)
300
- vol_serial = FFI::MemoryPointer.new(:ulong)
301
- name_max = FFI::MemoryPointer.new(:ulong)
302
- flags = FFI::MemoryPointer.new(:ulong)
302
+ vol_name_ptr = FFI::MemoryPointer.new(:char, MAXPATH)
303
+ base_type_ptr = FFI::MemoryPointer.new(:char, MAXPATH)
304
+ vol_serial_ptr = FFI::MemoryPointer.new(:ulong)
305
+ name_max_ptr = FFI::MemoryPointer.new(:ulong)
306
+ flags_ptr = FFI::MemoryPointer.new(:ulong)
303
307
 
304
308
  bool = GetVolumeInformationW(
305
- wpath,
306
- vol_name,
307
- vol_name.size,
308
- vol_serial,
309
- name_max,
310
- flags,
311
- base_type,
312
- base_type.size
309
+ mpoint.wincode,
310
+ vol_name_ptr,
311
+ vol_name_ptr.size,
312
+ vol_serial_ptr,
313
+ name_max_ptr,
314
+ flags_ptr,
315
+ base_type_ptr,
316
+ base_type_ptr.size
313
317
  )
314
318
 
315
319
  unless bool
316
320
  raise SystemCallError.new('GetVolumInformation', FFI.errno)
317
321
  end
318
322
 
319
- vol_serial = vol_serial.read_ulong
320
- name_max = name_max.read_ulong
321
- flags = flags.read_ulong
322
- base_type = base_type.read_string(base_type.size).tr(0.chr, '')
323
+ vol_serial = vol_serial_ptr.read_ulong
324
+ name_max = name_max_ptr.read_ulong
325
+ flags = flags_ptr.read_ulong
326
+ base_type = base_type_ptr.read_string(base_type_ptr.size).tr(0.chr, '')
327
+
328
+ vol_name_ptr.free
329
+ vol_serial_ptr.free
330
+ name_max_ptr.free
331
+ flags_ptr.free
332
+ base_type_ptr.free
323
333
 
324
334
  stat_obj = Stat.new
325
335
  stat_obj.instance_variable_set(:@path, path)
@@ -419,3 +429,7 @@ class Numeric
419
429
  self / 1099511627776
420
430
  end
421
431
  end
432
+
433
+ if $0 == __FILE__
434
+ p Sys::Filesystem.stat("C:/Users/djberge")
435
+ 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.2'
5
+ spec.version = '1.1.3'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.email = 'djberg96@gmail.com'
8
8
  spec.homepage = 'https://github.com/djberg96/sys-filesystem'
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency('rake')
20
20
 
21
21
  spec.description = <<-EOF
22
- The sys-filesystem library provides an interface for gathering filesystem
23
- information, such as disk space and mount point data.
22
+ The sys-filesystem library provides a cross-platform interface for
23
+ gathering filesystem information, such as disk space and mount point data.
24
24
  EOF
25
25
  end
@@ -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.2', Filesystem::VERSION)
28
+ assert_equal('1.1.3', Filesystem::VERSION)
29
29
  end
30
30
 
31
31
  def test_stat_path
@@ -11,7 +11,7 @@ include Sys
11
11
 
12
12
  class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
13
13
  def setup
14
- @dir = '/'
14
+ @dir = 'C:/'
15
15
  @stat = Filesystem.stat(@dir)
16
16
  @mount = Filesystem.mounts[0]
17
17
  @size = 58720256
@@ -19,12 +19,12 @@ 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.2', Filesystem::VERSION)
22
+ assert_equal('1.1.3', Filesystem::VERSION)
23
23
  end
24
24
 
25
25
  test "stat path works as expected" do
26
26
  assert_respond_to(@stat, :path)
27
- assert_equal("/", @stat.path)
27
+ assert_equal("C:/", @stat.path)
28
28
  end
29
29
 
30
30
  test "stat block_size works as expected" do
@@ -147,11 +147,19 @@ class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
147
147
  assert_not_nil(Filesystem::READ_ONLY_VOLUME)
148
148
  end
149
149
 
150
+ test "stat singleton method defaults to root path if proviced" do
151
+ assert_nothing_raised{ Filesystem.stat("C://Program Files") }
152
+ end
153
+
150
154
  test "stat singleton method requires a single argument" do
151
155
  assert_raise(ArgumentError){ Filesystem.stat }
152
156
  assert_raise(ArgumentError){ Filesystem.stat(Dir.pwd, Dir.pwd) }
153
157
  end
154
158
 
159
+ test "stat singleton method raises an error if path is not found" do
160
+ assert_raise(Errno::ESRCH){ Filesystem.stat("C://Bogus//Dir") }
161
+ end
162
+
155
163
  # Filesystem.mounts
156
164
 
157
165
  test "mounts singleton method basic functionality" do
metadata CHANGED
@@ -1,60 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-filesystem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
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: 2014-05-09 00:00:00.000000000 Z
11
+ date: 2014-10-02 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
55
  description: |2
56
- The sys-filesystem library provides an interface for gathering filesystem
57
- information, such as disk space and mount point data.
56
+ The sys-filesystem library provides a cross-platform interface for
57
+ gathering filesystem information, such as disk space and mount point data.
58
58
  email: djberg96@gmail.com
59
59
  executables: []
60
60
  extensions: []
@@ -89,17 +89,17 @@ require_paths:
89
89
  - lib
90
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ">="
92
+ - - '>='
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">="
97
+ - - '>='
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubyforge_project: sysutils
102
- rubygems_version: 2.2.2
102
+ rubygems_version: 2.4.1
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: A Ruby interface for getting file system information.