sys-filesystem 1.4.3 → 1.5.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +14 -0
- data/README.md +1 -1
- data/Rakefile +13 -0
- data/lib/sys/filesystem.rb +17 -16
- data/lib/sys/unix/sys/filesystem/constants.rb +4 -0
- data/lib/sys/unix/sys/filesystem/functions.rb +19 -23
- data/lib/sys/unix/sys/filesystem/structs.rb +138 -91
- data/lib/sys/unix/sys/filesystem.rb +67 -52
- data/lib/sys/windows/sys/filesystem/functions.rb +1 -0
- data/lib/sys/windows/sys/filesystem/helper.rb +3 -0
- data/lib/sys/windows/sys/filesystem.rb +13 -11
- data/lib/sys-filesystem.rb +2 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/sys_filesystem_shared.rb +14 -0
- data/spec/sys_filesystem_unix_spec.rb +266 -135
- data/spec/sys_filesystem_windows_spec.rb +263 -151
- data/sys-filesystem.gemspec +15 -7
- data.tar.gz.sig +0 -0
- metadata +34 -3
- metadata.gz.sig +2 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
# Reopen core Ruby classes here and add some custom methods.
|
|
1
2
|
class String
|
|
2
3
|
# Convenience method for converting strings to UTF-16LE for wide character
|
|
3
4
|
# functions that require it.
|
|
5
|
+
#--
|
|
6
|
+
# TODO: Use a refinement.
|
|
4
7
|
def wincode
|
|
5
8
|
(tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
|
|
6
9
|
end
|
|
@@ -9,7 +9,6 @@ require 'time'
|
|
|
9
9
|
|
|
10
10
|
# The Sys module serves as a namespace only.
|
|
11
11
|
module Sys
|
|
12
|
-
|
|
13
12
|
# The Filesystem class encapsulates information about your filesystem.
|
|
14
13
|
class Filesystem
|
|
15
14
|
include Sys::Filesystem::Constants
|
|
@@ -20,6 +19,7 @@ module Sys
|
|
|
20
19
|
|
|
21
20
|
private_class_method :new
|
|
22
21
|
|
|
22
|
+
# Mount objects are returned by the Sys::Filesystem.mounts method.
|
|
23
23
|
class Mount
|
|
24
24
|
# The name of the volume. This is the device mapping.
|
|
25
25
|
attr_reader :name
|
|
@@ -50,6 +50,7 @@ module Sys
|
|
|
50
50
|
alias freq frequency
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
# Stat objects are returned by the Sys::Filesystem.stat method.
|
|
53
54
|
class Stat
|
|
54
55
|
# The path of the file system.
|
|
55
56
|
attr_reader :path
|
|
@@ -160,6 +161,8 @@ module Sys
|
|
|
160
161
|
#--
|
|
161
162
|
# I couldn't really find a good reason to use the wide functions for this
|
|
162
163
|
# method. If you have one, patches welcome.
|
|
164
|
+
#--
|
|
165
|
+
# rubocop:disable Metrics/BlockLength
|
|
163
166
|
#
|
|
164
167
|
def self.mounts
|
|
165
168
|
# First call, get needed buffer size
|
|
@@ -196,14 +199,14 @@ module Sys
|
|
|
196
199
|
filesystem_flags = FFI::MemoryPointer.new(:ulong)
|
|
197
200
|
|
|
198
201
|
bool = GetVolumeInformationA(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
drive,
|
|
203
|
+
volume,
|
|
204
|
+
volume.size,
|
|
205
|
+
volume_serial_number,
|
|
206
|
+
max_component_length,
|
|
207
|
+
filesystem_flags,
|
|
208
|
+
fsname,
|
|
209
|
+
fsname.size
|
|
207
210
|
)
|
|
208
211
|
|
|
209
212
|
# Skip unmounted floppies or cd-roms, or inaccessible drives
|
|
@@ -237,6 +240,7 @@ module Sys
|
|
|
237
240
|
|
|
238
241
|
mounts # Nil if the block form was used.
|
|
239
242
|
end
|
|
243
|
+
# rubocop:enable Metrics/BlockLength
|
|
240
244
|
|
|
241
245
|
# Returns the mount point for the given +file+. For MS Windows this
|
|
242
246
|
# means the root of the path.
|
|
@@ -250,8 +254,6 @@ module Sys
|
|
|
250
254
|
|
|
251
255
|
if PathStripToRootW(wfile)
|
|
252
256
|
wfile.read_string(wfile.size).split("\000\000").first.tr(0.chr, '')
|
|
253
|
-
else
|
|
254
|
-
nil
|
|
255
257
|
end
|
|
256
258
|
end
|
|
257
259
|
|
data/lib/sys-filesystem.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rspec'
|
|
4
|
+
require 'sys_filesystem_shared'
|
|
2
5
|
|
|
3
6
|
RSpec.configure do |config|
|
|
7
|
+
config.include_context(Sys::Filesystem)
|
|
4
8
|
config.filter_run_excluding(:windows) unless Gem.win_platform?
|
|
5
9
|
config.filter_run_excluding(:unix) if Gem.win_platform?
|
|
10
|
+
config.filter_run_excluding(:dragonfly) unless RbConfig::CONFIG['host_os'] =~ /dragonfly/i
|
|
6
11
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'sys-filesystem'
|
|
4
|
+
|
|
5
|
+
RSpec.shared_examples Sys::Filesystem do
|
|
6
|
+
example 'version number is set to the expected value' do
|
|
7
|
+
expect(Sys::Filesystem::VERSION).to eq('1.5.0')
|
|
8
|
+
expect(Sys::Filesystem::VERSION).to be_frozen
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
example 'you cannot instantiate an instance' do
|
|
12
|
+
expect{ described_class.new }.to raise_error(NoMethodError)
|
|
13
|
+
end
|
|
14
|
+
end
|