hrr_rb_mount 0.1.0 → 0.2.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
- data/.travis.yml +2 -2
- data/README.md +4 -2
- data/ext/hrr_rb_mount/hrr_rb_mount.c +4 -4
- data/lib/hrr_rb_mount/version.rb +1 -1
- data/lib/hrr_rb_mount.rb +50 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e40e0f523c2e10f4590e65254da3c1533347ddc07bd085543d331434b221449
|
4
|
+
data.tar.gz: 557b4ac323a0c85c71e077fc87d85c1e6f23d29886b442c4ae0a45e40104526a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2b316d880055d67c37d9e9230a36df9f6abb8d585fcc5cd9bd27f15a859c92734b4676047d21f7e96a64d14615ae02bdf5dde48434a6be43afbd3451aebccea
|
7
|
+
data.tar.gz: cbe8545e911c7cdfc686ad545f22a85d62c01a5e727b3616786b4d8e5447a451cc2a2a0891613478e4b137b61b415b09179eb462362622734b80df82310c22b4
|
data/.travis.yml
CHANGED
@@ -23,8 +23,8 @@ before_install:
|
|
23
23
|
install:
|
24
24
|
- bundle install
|
25
25
|
before_script:
|
26
|
-
- bundle exec rake clean clobber
|
26
|
+
- sudo env RBENV_VERSION="${RBENV_VERSION}" PATH="${RBENV_ROOT}/shims:${RBENV_ROOT}/bin:${PATH}" bundle exec rake clean clobber
|
27
27
|
script:
|
28
28
|
- sudo env RBENV_VERSION="${RBENV_VERSION}" PATH="${RBENV_ROOT}/shims:${RBENV_ROOT}/bin:${PATH}" bundle exec rake compile spec
|
29
29
|
after_script:
|
30
|
-
- bundle exec rake clean clobber
|
30
|
+
- sudo env RBENV_VERSION="${RBENV_VERSION}" PATH="${RBENV_ROOT}/shims:${RBENV_ROOT}/bin:${PATH}" bundle exec rake clean clobber
|
data/README.md
CHANGED
@@ -37,8 +37,10 @@ The basic usage is as follows.
|
|
37
37
|
```ruby
|
38
38
|
require "hrr_rb_mount"
|
39
39
|
|
40
|
-
|
41
|
-
HrrRbMount.
|
40
|
+
flags = HrrRbMount::NOEXEC
|
41
|
+
HrrRbMount.mount "tmpfs", "/path/to/target", "tmpfs", flags, "size=1M" # => 0
|
42
|
+
HrrRbMount.mountpoint? "/path/to/target" # => true
|
43
|
+
HrrRbMount.umount "/path/to/target" # => 0
|
42
44
|
```
|
43
45
|
|
44
46
|
## Development
|
@@ -15,14 +15,14 @@ VALUE rb_mHrrRbMountConst;
|
|
15
15
|
* @param target [String] The location (a directory or file) specified by the pathname.
|
16
16
|
* @param filesystemtype [String] The filesystem type, which is supported by the kernel.
|
17
17
|
* @param mountflags [Integer] The mount operation is performed depending on the bits specified in the mountflags.
|
18
|
-
* @param data [
|
18
|
+
* @param data [String] Per filesystem options.
|
19
19
|
* @return [Integer] 0.
|
20
20
|
* @raise [Errno::EXXX] A SystemCallError is raised when the operation failed.
|
21
21
|
*/
|
22
22
|
VALUE
|
23
23
|
hrr_rb_mount_mount(int argc, VALUE *argv, VALUE self)
|
24
24
|
{
|
25
|
-
char *source, *target, *filesystemtype, *data;
|
25
|
+
const char *source, *target, *filesystemtype, *data;
|
26
26
|
unsigned long mountflags;
|
27
27
|
|
28
28
|
rb_check_arity(argc, 3, 5);
|
@@ -54,8 +54,8 @@ hrr_rb_mount_mount(int argc, VALUE *argv, VALUE self)
|
|
54
54
|
VALUE
|
55
55
|
hrr_rb_mount_umount(int argc, VALUE *argv, VALUE self)
|
56
56
|
{
|
57
|
-
char *target;
|
58
|
-
int
|
57
|
+
const char *target;
|
58
|
+
int flags;
|
59
59
|
|
60
60
|
rb_check_arity(argc, 1, 2);
|
61
61
|
|
data/lib/hrr_rb_mount/version.rb
CHANGED
data/lib/hrr_rb_mount.rb
CHANGED
@@ -1,7 +1,55 @@
|
|
1
1
|
require "hrr_rb_mount/version"
|
2
2
|
require "hrr_rb_mount/hrr_rb_mount"
|
3
3
|
|
4
|
-
# A wrapper around mount and umount.
|
5
|
-
#
|
4
|
+
# A wrapper around mount and umount. See mount(2) and umount(2) for details.
|
5
|
+
#
|
6
|
+
# == Synopsis:
|
7
|
+
# require "hrr_rb_mount"
|
8
|
+
#
|
9
|
+
# flags = HrrRbMount::NOEXEC
|
10
|
+
# HrrRbMount.mount "tmpfs", "/path/to/target", "tmpfs", flags, "size=1M" # => 0
|
11
|
+
# HrrRbMount.mountpoint? "/path/to/target" # => true
|
12
|
+
# HrrRbMount.umount "/path/to/target" # => 0
|
13
|
+
#
|
6
14
|
module HrrRbMount
|
15
|
+
|
16
|
+
# Constants that represent the flags for mount and umount operations.
|
17
|
+
module Constants
|
18
|
+
end
|
19
|
+
|
20
|
+
# The path to /proc/self/mountinfo.
|
21
|
+
PROC_MOUNTINFO_PATH = "/proc/self/mountinfo"
|
22
|
+
|
23
|
+
# Returns true if the target directory or file is a mountpoint. Otherwise, returns false.
|
24
|
+
#
|
25
|
+
# Internally, uses /proc/self/mountinfo file to detect if the target is a mountpoint.
|
26
|
+
#
|
27
|
+
# When the file is not available, then uses stat(2).
|
28
|
+
# In this case, bind mount is not able to be detected.
|
29
|
+
#
|
30
|
+
# == Synopsis:
|
31
|
+
# HrrRbMount.mountpoint? "/proc" # => true
|
32
|
+
# HrrRbMount.mountpoint? "/proc/1" # => false
|
33
|
+
#
|
34
|
+
# @param target [String] The target path to be checked.
|
35
|
+
# @param follow_symlinks [Boolean] Specifies whether to follow symlinks.
|
36
|
+
# @return [Boolean] true or false
|
37
|
+
# @raise [Errno::EXXX] A SystemCallError is raised when the operation failed.
|
38
|
+
def self.mountpoint? target, follow_symlinks: true
|
39
|
+
return false if (! follow_symlinks) && File.symlink?(target)
|
40
|
+
begin
|
41
|
+
if File.exist? PROC_MOUNTINFO_PATH
|
42
|
+
tgt_abs_path = File.realpath(target)
|
43
|
+
File.foreach(PROC_MOUNTINFO_PATH){ |line|
|
44
|
+
break true if line.split(" ")[4] == tgt_abs_path
|
45
|
+
} or false
|
46
|
+
else
|
47
|
+
parent = File.join(target, "..")
|
48
|
+
st, pst = File.stat(target), File.stat(parent)
|
49
|
+
st.dev != pst.dev || st.ino == pst.ino
|
50
|
+
end
|
51
|
+
rescue Errno::ENOENT, Errno::ENOTDIR
|
52
|
+
false
|
53
|
+
end
|
54
|
+
end
|
7
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hrr_rb_mount
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A wrapper around mount and umount for CRuby
|
14
14
|
email:
|