sys-filesystem 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7c3f0edc5663aaad12f5efe558ade7e4b60d501a76da48d1620141f08196800
4
- data.tar.gz: 6f5ba4a40c49bbbbf0a93607713a314f9f4c5cc88d8d9748f0b0d40c50ce97f7
3
+ metadata.gz: f47e78baa2a2d0586d9dccbe36fc98a2683f0f0cc9828d70317ba7d2dc2aaa40
4
+ data.tar.gz: 8a887956f1a3c621057e93960e67871c646ae00f7cfe157d21ee0fd0f7d21bc7
5
5
  SHA512:
6
- metadata.gz: cd8722d5a57207ec407585cc6c92087cd8dcdb844e8e5c5acec6be7688fa2170fccb4036c6395552081378b6d00bd70cb4dae6b9fae30728e3118d972d425ef8
7
- data.tar.gz: caff95ccc96dd102f379a1c48d15b00111e75d3c5069330cf0d02bc0096d84f3601efc667bb58a8ac43c9651e4548b3fdd51f58814b1b8e8c6c0148c71d73e1d
6
+ metadata.gz: 66a048e0249d7147868c2a3a21468f5f292be47e82d19316d00d7dc5deab8a4c961bd363c55c55ac7e83d8992a0ecc71a3579ec4ca6e7a874308bd7f5e727aa7
7
+ data.tar.gz: 76ba77a00a187654367b01cacf2c282959fdbcaa3b2646075687a4f842ade1926bab0b38c51e60ac7b582f0633ce9ff27e32c349720788988a0e48cc5915c27a
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.3.0 - 3-Oct-2019
2
+ * Added the mount and umount singleton methods.
3
+ * Changed an internal class variable to a frozen constant.
4
+
1
5
  == 1.2.0 - 1-Jan-2019
2
6
  * Changed the license to Apache-2.0.
3
7
  * Added the case_sensitive? and case_insensitive? instance methods to the
data/README CHANGED
@@ -59,10 +59,10 @@
59
59
  Nobuyoshi Miyokawa, for adding the original FreeBSD and OS X support.
60
60
 
61
61
  = License
62
- Artistic 2.0
62
+ Apache-2.0
63
63
 
64
64
  = Copyright
65
- (C) 2003-2018 Daniel J. Berger
65
+ (C) 2003-2019 Daniel J. Berger
66
66
  All Rights Reserved
67
67
 
68
68
  = Warranty
@@ -1,7 +1,7 @@
1
1
  module Sys
2
2
  class Filesystem
3
3
  # The version of the sys-filesystem library
4
- VERSION = '1.2.0'.freeze
4
+ VERSION = '1.3.0'.freeze
5
5
  end
6
6
  end
7
7
 
@@ -14,7 +14,7 @@ module Sys
14
14
  private
15
15
 
16
16
  # Readable versions of constant names
17
- @@opt_names = {
17
+ OPT_NAMES = {
18
18
  MNT_RDONLY => 'read-only',
19
19
  MNT_SYNCHRONOUS => 'synchronous',
20
20
  MNT_NOEXEC => 'noexec',
@@ -35,7 +35,7 @@ module Sys
35
35
  MNT_NOUSERXATTR => 'nouserxattr',
36
36
  MNT_DEFWRITE => 'defwrite',
37
37
  MNT_NOATIME => 'noatime'
38
- }
38
+ }.freeze
39
39
 
40
40
  # File used to read mount informtion from.
41
41
  if File.exist?('/etc/mtab')
@@ -268,7 +268,7 @@ module Sys
268
268
  string = ""
269
269
  flags = mnt[:f_flags] & MNT_VISFLAGMASK
270
270
 
271
- @@opt_names.each{ |key,val|
271
+ OPT_NAMES.each{ |key,val|
272
272
  if flags & key > 0
273
273
  if string.empty?
274
274
  string << val
@@ -379,5 +379,50 @@ module Sys
379
379
 
380
380
  val
381
381
  end
382
+
383
+ # Attach the filesystem specified by +source+ to the location (a directory
384
+ # or file) specified by the pathname in +target+.
385
+ #
386
+ # Note that the +source+ is often a pathname referring to a device, but
387
+ # can also be the pathname of a directory or file, or a dummy string.
388
+ #
389
+ # By default this method will assume 'ext2' as the filesystem type, but
390
+ # you should update this as needed.
391
+ #
392
+ # Typically requires admin privileges.
393
+ #
394
+ # Example:
395
+ #
396
+ # Sys::Filesystem.mount('/dev/loop0', '/home/you/tmp', 'ext4', Sys::Filesystem::MNT_RDONLY)
397
+ #
398
+ def self.mount(source, target, fstype = 'ext2', flags = 0, data = nil)
399
+ if mount_c(source, target, fstype, flags, data) != 0
400
+ raise Error, 'mount() function failed: ' + strerror(FFI.errno)
401
+ end
402
+
403
+ self
404
+ end
405
+
406
+ # Removes the attachment of the (topmost) filesystem mounted on target.
407
+ # Additional flags may be provided for operating systems that support
408
+ # the umount2 function. Otherwise this argument is ignored.
409
+ #
410
+ # Typically requires admin privileges.
411
+ #
412
+ def self.umount(target, flags = nil)
413
+ if flags && respond_to?(:umount2)
414
+ function = 'umount2'
415
+ rv = umount2_c(target, flags)
416
+ else
417
+ function = 'umount'
418
+ rv = umount_c(target)
419
+ end
420
+
421
+ if rv != 0
422
+ raise Error, "#{function} function failed: " + strerror(FFI.errno)
423
+ end
424
+
425
+ self
426
+ end
382
427
  end
383
428
  end
@@ -36,6 +36,37 @@ module Sys
36
36
  MNT_NOUSERXATTR | MNT_DEFWRITE | MNT_MULTILABEL |
37
37
  MNT_NOATIME | MNT_CPROTECT
38
38
  )
39
+
40
+ MS_RDONLY = 1
41
+ MS_NOSUID = 2
42
+ MS_NODEV = 4
43
+ MS_NOEXEC = 8
44
+ MS_SYNCHRONOUS = 16
45
+ MS_REMOUNT = 32
46
+ MS_MANDLOCK = 64
47
+ MS_DIRSYNC = 128
48
+ MS_NOATIME = 1024
49
+ MS_NODIRATIME = 2048
50
+ MS_BIND = 4096
51
+ MS_MOVE = 8192
52
+ MS_REC = 16384
53
+ MS_SILENT = 32768
54
+ MS_POSIXACL = 1 << 16
55
+ MS_UNBINDABLE = 1 << 17
56
+ MS_PRIVATE = 1 << 18
57
+ MS_SLAVE = 1 << 19
58
+ MS_SHARED = 1 << 20
59
+ MS_RELATIME = 1 << 21
60
+ MS_KERNMOUNT = 1 << 22
61
+ MS_I_VERSION = 1 << 23
62
+ MS_STRICTATIME = 1 << 24
63
+ MS_ACTIVE = 1 << 30
64
+ MS_NOUSER = 1 << 31
65
+
66
+ MNT_FORCE = 1
67
+ MNT_DETACH = 2
68
+ MNT_EXPIRE = 4
69
+ UMOUNT_NOFOLLOW = 8
39
70
  end
40
71
  end
41
72
  end
@@ -14,8 +14,17 @@ module Sys
14
14
  end
15
15
 
16
16
  attach_function(:strerror, [:int], :string)
17
+ attach_function(:mount_c, :mount, [:string, :string, :string, :ulong, :string], :int)
17
18
 
18
- private_class_method :statvfs, :strerror
19
+ begin
20
+ attach_function(:umount_c, :umount, [:string], :int)
21
+ rescue FFI::NotFoundError
22
+ if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach/i
23
+ attach_function(:umount_c, :unmount, [:string], :int)
24
+ end
25
+ end
26
+
27
+ private_class_method :statvfs, :strerror, :mount_c, :umount_c
19
28
 
20
29
  begin
21
30
  if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
@@ -27,7 +36,8 @@ module Sys
27
36
  attach_function(:getmntent, [:pointer], :pointer)
28
37
  attach_function(:setmntent, [:string, :string], :pointer)
29
38
  attach_function(:endmntent, [:pointer], :int)
30
- private_class_method :getmntent, :setmntent, :endmntent
39
+ attach_function(:umount2, [:string, :int], :int)
40
+ private_class_method :getmntent, :setmntent, :endmntent, :umount2
31
41
  end
32
42
  rescue FFI::NotFoundError
33
43
  if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach/i
@@ -353,6 +353,35 @@ module Sys
353
353
  stat_obj.freeze # Read-only object
354
354
  end
355
355
 
356
+ # Associate a volume with a drive letter or a directory on another volume.
357
+ #
358
+ def self.mount(target, source)
359
+ targetw = target.to_s.wincode
360
+ sourcew = source.to_s.wincode
361
+
362
+ volume_namew = (0.chr * 256).wincode
363
+
364
+ unless GetVolumeNameForVolumeMountPointW(sourcew, volume_namew, volume_namew.size)
365
+ raise SystemCallError.new('GetVolumeNameForVolumeMountPoint', FFI.errno)
366
+ end
367
+
368
+ unless SetVolumeMountPointW(targetw, volume_namew)
369
+ raise SystemCallError.new('SetVolumeMountPoint', FFI.errno)
370
+ end
371
+
372
+ self
373
+ end
374
+
375
+ # Deletes a drive letter or mounted folder.
376
+ #
377
+ def self.umount(mount_point)
378
+ unless DeleteVolumeMountPoint(mount_point)
379
+ raise SystemCallError.new('DeleteVolumeMountPoint', FFI.errno)
380
+ end
381
+
382
+ self
383
+ end
384
+
356
385
  private
357
386
 
358
387
  # This method is used to get the boot time of the system, which is used
@@ -14,6 +14,7 @@ module Sys
14
14
  end
15
15
  end
16
16
 
17
+ attach_pfunc :DeleteVolumeMountPointA, [:string], :bool
17
18
  attach_pfunc :GetDiskFreeSpaceW, [:buffer_in, :pointer, :pointer, :pointer, :pointer], :bool
18
19
  attach_pfunc :GetDiskFreeSpaceExW, [:buffer_in, :pointer, :pointer, :pointer], :bool
19
20
  attach_pfunc :GetLogicalDriveStringsA, [:ulong, :pointer], :ulong
@@ -26,7 +27,9 @@ module Sys
26
27
  [:buffer_in, :pointer, :ulong, :pointer, :pointer, :pointer, :pointer, :ulong],
27
28
  :bool
28
29
 
30
+ attach_pfunc :GetVolumeNameForVolumeMountPointW, [:buffer_in, :buffer_in, :ulong], :bool
29
31
  attach_pfunc :QueryDosDeviceA, [:buffer_in, :buffer_out, :ulong], :ulong
32
+ attach_pfunc :SetVolumeMountPointW, [:buffer_in, :buffer_in], :bool
30
33
 
31
34
  ffi_lib :shlwapi
32
35
 
@@ -2,12 +2,12 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sys-filesystem'
5
- spec.version = '1.2.0'
5
+ spec.version = '1.3.0'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.email = 'djberg96@gmail.com'
8
8
  spec.homepage = 'https://github.com/djberg96/sys-filesystem'
9
9
  spec.summary = 'A Ruby interface for getting file system information.'
10
- spec.test_file = 'test/test_sys_filesystem.rb'
10
+ spec.test_files = Dir['test/*.rb']
11
11
  spec.license = 'Apache-2.0'
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
  spec.cert_chain = Dir['certs/*']
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.metadata = {
22
22
  'homepage_uri' => 'https://github.com/djberg96/sys-filesystem',
23
23
  'bug_tracker_uri' => 'https://github.com/djberg96/sys-filesystem/issues',
24
- 'changelog_uri' => 'https://github.com/djberg96/sys-filesystem/blob/master/CHANGES',
24
+ 'changelog_uri' => 'https://github.com/djberg96/sys-filesystem/blob/ffi/CHANGES',
25
25
  'documentation_uri' => 'https://github.com/djberg96/sys-filesystem/wiki',
26
26
  'source_code_uri' => 'https://github.com/djberg96/sys-filesystem',
27
27
  'wiki_uri' => 'https://github.com/djberg96/sys-filesystem/wiki'
@@ -25,7 +25,8 @@ class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def test_version
28
- assert_equal('1.2.0', Filesystem::VERSION)
28
+ assert_equal('1.3.0', Filesystem::VERSION)
29
+ assert_true(Filesystem::VERSION.frozen?)
29
30
  end
30
31
 
31
32
  def test_stat_path
@@ -282,6 +283,14 @@ class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
282
283
  assert_false(Filesystem.methods.include?('strerror'))
283
284
  end
284
285
 
286
+ def test_mount_singleton_method
287
+ assert_respond_to(Sys::Filesystem, :mount)
288
+ end
289
+
290
+ def test_umount_singleton_method
291
+ assert_respond_to(Sys::Filesystem, :umount)
292
+ end
293
+
285
294
  def teardown
286
295
  @dir = nil
287
296
  @stat = nil
@@ -20,7 +20,8 @@ class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
20
20
  end
21
21
 
22
22
  test "version number is set to the expected value" do
23
- assert_equal('1.2.0', Filesystem::VERSION)
23
+ assert_equal('1.3.0', Filesystem::VERSION)
24
+ assert_true(Filesystem::VERSION.frozen?)
24
25
  end
25
26
 
26
27
  test "stat path works as expected" do
@@ -275,6 +276,16 @@ class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
275
276
  assert_equal(0, @size.to_gb)
276
277
  end
277
278
 
279
+ # Mount and Unmount
280
+
281
+ test "mount singleton method exists" do
282
+ assert_respond_to(Sys::Filesystem, :mount)
283
+ end
284
+
285
+ test "umount singleton method exists" do
286
+ assert_respond_to(Sys::Filesystem, :umount)
287
+ end
288
+
278
289
  # FFI
279
290
 
280
291
  test "internal ffi functions are not public" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-filesystem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2019-01-01 00:00:00.000000000 Z
38
+ date: 2019-10-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
@@ -91,20 +91,12 @@ extra_rdoc_files:
91
91
  - MANIFEST
92
92
  files:
93
93
  - test
94
- - test/test_sys_filesystem_windows.rb
95
- - test/test_sys_filesystem_unix.rb
96
94
  - test/test_sys_filesystem.rb
97
- - CHANGES
98
- - MANIFEST
99
- - README
100
- - Rakefile
101
- - sys-filesystem.gemspec
102
- - certs
103
- - certs/djberg96_pub.pem
95
+ - test/test_sys_filesystem_unix.rb
96
+ - test/test_sys_filesystem_windows.rb
104
97
  - examples
105
98
  - examples/example_stat.rb
106
99
  - lib
107
- - lib/sys-filesystem.rb
108
100
  - lib/sys
109
101
  - lib/sys/unix
110
102
  - lib/sys/unix/sys
@@ -113,21 +105,29 @@ files:
113
105
  - lib/sys/unix/sys/filesystem/constants.rb
114
106
  - lib/sys/unix/sys/filesystem/functions.rb
115
107
  - lib/sys/unix/sys/filesystem.rb
116
- - lib/sys/filesystem.rb
117
108
  - lib/sys/windows
118
109
  - lib/sys/windows/sys
119
110
  - lib/sys/windows/sys/filesystem
120
- - lib/sys/windows/sys/filesystem/helper.rb
121
111
  - lib/sys/windows/sys/filesystem/constants.rb
112
+ - lib/sys/windows/sys/filesystem/helper.rb
122
113
  - lib/sys/windows/sys/filesystem/functions.rb
123
114
  - lib/sys/windows/sys/filesystem.rb
115
+ - lib/sys/filesystem.rb
116
+ - lib/sys-filesystem.rb
117
+ - MANIFEST
118
+ - README
119
+ - Rakefile
120
+ - certs
121
+ - certs/djberg96_pub.pem
122
+ - CHANGES
123
+ - sys-filesystem.gemspec
124
124
  homepage: https://github.com/djberg96/sys-filesystem
125
125
  licenses:
126
126
  - Apache-2.0
127
127
  metadata:
128
128
  homepage_uri: https://github.com/djberg96/sys-filesystem
129
129
  bug_tracker_uri: https://github.com/djberg96/sys-filesystem/issues
130
- changelog_uri: https://github.com/djberg96/sys-filesystem/blob/master/CHANGES
130
+ changelog_uri: https://github.com/djberg96/sys-filesystem/blob/ffi/CHANGES
131
131
  documentation_uri: https://github.com/djberg96/sys-filesystem/wiki
132
132
  source_code_uri: https://github.com/djberg96/sys-filesystem
133
133
  wiki_uri: https://github.com/djberg96/sys-filesystem/wiki
@@ -147,9 +147,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.7.6
150
+ rubygems_version: 2.7.6.2
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: A Ruby interface for getting file system information.
154
154
  test_files:
155
155
  - test/test_sys_filesystem.rb
156
+ - test/test_sys_filesystem_unix.rb
157
+ - test/test_sys_filesystem_windows.rb
metadata.gz.sig CHANGED
Binary file