hrr_rb_mount 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: e185f431ad5671235bcc254acd3de74dcb3edb0bce64146b696f2e8aba6725d2
4
- data.tar.gz: 16616492c26c1e57b0eaeda5b31d2e9ac35be9a6519cf7da16dfad4024da59a6
3
+ metadata.gz: 7e40e0f523c2e10f4590e65254da3c1533347ddc07bd085543d331434b221449
4
+ data.tar.gz: 557b4ac323a0c85c71e077fc87d85c1e6f23d29886b442c4ae0a45e40104526a
5
5
  SHA512:
6
- metadata.gz: 9aa7073175f1addc4cb0c8776cc49ecaa66e8e1f466ecb177a67583459a96c5de74794550ef108276a939be068bc116b5c23405ac20ad97172ae925fee0d46b8
7
- data.tar.gz: 9d195d10507fedd27c89a41566d2d55b9a546abff16b656f5efe012d5fe9c4bacdb286167e60df4ad14678195eac0340cc02ab187987a6e45187f8f82b85e287
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
- HrrRbMount.mount "tmpfs", "/path/to/target", "tmpfs", HrrRbMount::NOEXEC, "size=1M" # => 0
41
- HrrRbMount.umount "/path/to/target" # => 0
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 [Array] Per filesystem options.
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 flags;
57
+ const char *target;
58
+ int flags;
59
59
 
60
60
  rb_check_arity(argc, 1, 2);
61
61
 
@@ -1,3 +1,3 @@
1
1
  module HrrRbMount
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
- # See mount(2) and umount(2) for details.
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.1.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-08 00:00:00.000000000 Z
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: