fakefs 0.17.0 → 0.18.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: 2615742cb54b7cea91ad40e51e1b1baf037ea9295eff338b0432fc20f1ea9483
4
- data.tar.gz: e9e136d1eb2d10a18b0470ed45c8058b88656af040d45136f78a53fb21bf42c0
3
+ metadata.gz: 9479bf3a7bc17238053ebfe0489449a54eaf93975c253873caa817cb608a6e12
4
+ data.tar.gz: e0071c3db4a4b16278a995b0f1ecce76a6781ce23847ef67194a0edb2f2999e2
5
5
  SHA512:
6
- metadata.gz: 790f25734bd4b9bf2c4b82750421bbe40114a591efa327b909b61e0ef341360f5bdbde7c5d99c06a3931f46d655710f1fc7c302a24b67590cb849e506e750450
7
- data.tar.gz: 73578d236fa95d8307311c87c9fba693c101295bdc915b2bc6adda0c074e9ea5eb782121af5cc3c3446cf8292d57a6ed8dd5c6979a4cdee9be2fb11053c4b65c
6
+ metadata.gz: 03be56fc4d1a9f05d410e75f2292cb498c0522f9a40508a28763ec757a5b6bf011be8c1462b52292987ea5f594ed54f04f64e1a4baefac2768c4db318ae5f389
7
+ data.tar.gz: 7fdd408a1814b6629271d4de1c9610c77836e9d1d8a3dfec8c7c4667bfa4d5fd02e5ed5b85aa111de3e5d5a84808c97b8ced730d2c4cbbad995cb87b703b3014
@@ -60,10 +60,12 @@ module FakeFS
60
60
  end
61
61
 
62
62
  def self.readable?(path)
63
+ return false unless exist? path
63
64
  File.lstat(path).readable?
64
65
  end
65
66
 
66
67
  def self.writable?(path)
68
+ return false unless exist? path
67
69
  File.lstat(path).writable?
68
70
  end
69
71
 
@@ -281,8 +283,15 @@ module FakeFS
281
283
  RealFile.split(path)
282
284
  end
283
285
 
284
- def self.chmod(mode_int, filename)
285
- FileSystem.find(filename).mode = 0o100000 + mode_int
286
+ def self.chmod(mode, filename)
287
+ # chmod's mode can either be passed in in absolute mode, or symbolic mode
288
+ # for reference: https://ruby-doc.org/stdlib-2.2.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-chmod
289
+ # if the mode is passed in symbolic mode we must convert it to absolute mode
290
+ is_absolute_mode = mode.is_a? Numeric
291
+ unless is_absolute_mode
292
+ mode = convert_symbolic_chmod_to_absolute mode
293
+ end
294
+ FileSystem.find(filename).mode = 0o100000 + mode
286
295
  end
287
296
 
288
297
  # Not exactly right, returns true if the file is chmod +x for owner. In the
@@ -567,8 +576,15 @@ module FakeFS
567
576
  self.class.mtime(@path)
568
577
  end
569
578
 
570
- def chmod(mode_int)
571
- @file.mode = 0o100000 + mode_int
579
+ def chmod(mode)
580
+ # chmod's mode can either be passed in in absolute mode, or symbolic mode
581
+ # for reference: https://ruby-doc.org/stdlib-2.2.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-chmod
582
+ # if the mode is passed in symbolic mode we must convert it to absolute mode
583
+ is_absolute_mode = mode.is_a? Numeric
584
+ unless is_absolute_mode
585
+ mode = convert_symbolic_chmod_to_absolute mode
586
+ end
587
+ @file.mode = 0o100000 + mode
572
588
  end
573
589
 
574
590
  def chown(owner_int, group_int)
@@ -672,6 +688,78 @@ module FakeFS
672
688
  read_buf
673
689
  end
674
690
 
691
+ def self.convert_symbolic_chmod_to_absolute(mode)
692
+ # mode always must be of form <GROUP1>=<FLAGS>,<GROUP2>=<FLAGS,...
693
+ # e.g.: u=wr,go=x
694
+ chmod_pairs = mode.split(',')
695
+
696
+ # - duplicating groups is OK ( e.g.: 'ugouuoouu' is valid and is interpretted as 'ugo' )
697
+ # - duplicating modes is OK ( e.g.: 'wwwwwwwww' is interpreted as 'w' )
698
+ # - omitting the right hand side is interpretted as removing all permission
699
+ # ( e.g.: 'ugo=' is really 'chmod 000' )
700
+ # - omitting the left hand side is interpretted as all groups ( e.g.: '=rwx' is really 'ugo=rwx' )
701
+ # - if we list a group more than once, we only apply the rightmost permissions
702
+ # ( e.g.: 'ug=rx,g=x' is really 'u=r,g=x' )
703
+ # - we cannot list any flags that are not 'rwx' ( e.g.: converting 'ug=rwx' to 'ug=7' is invalid )
704
+ # or else an error is raised
705
+ # - in the example above, the following error is raised: 'invalid `perm' symbol in file mode: 7 (ArgumentError)'
706
+ # - we cannot put in any groups that are not 'ugo' ( e.g.: listing groups as 'uzg=x' is invalid )
707
+ # or else an error is raised
708
+ # - in the example above, the following error is raised: 'invalid `who' symbol in file mode: z (ArgumentError)'
709
+ valid_groups_to_numeric_vals = { 'u' => 0o100, 'g' => 0o10, 'o' => 0o1 }
710
+ current_groups_to_vals = { 0o100 => 0o0, 0o10 => 0o0, 0o1 => 0o0 }
711
+ valid_modes_to_numeric_vals = { 'r' => 0o4, 'w' => 0o2, 'x' => 0o1 }
712
+ chmod_pairs.each do |pair|
713
+ groups = pair.rpartition('=').first
714
+ modes = pair.rpartition('=').last
715
+
716
+ # if we give no modes, then we are removing all permission
717
+ chmod_perm_num = 0o0
718
+ if modes != ''
719
+ # make sure there are no invalid flags in the modes
720
+ # and that we discard duplicates as chmod does
721
+ given_modes = modes.split('')
722
+ given_modes = given_modes.uniq
723
+ given_modes.each do |specific_mode|
724
+ # ensure that the mode is valid
725
+ unless valid_modes_to_numeric_vals.key? specific_mode
726
+ raise ArgumentError, "Invalid `perm' symbol in file mode: #{specific_mode}"
727
+ end
728
+
729
+ chmod_addend = valid_modes_to_numeric_vals[specific_mode]
730
+ chmod_perm_num += chmod_addend
731
+ end
732
+ end
733
+
734
+ # if we give no groups, then we are giving all groups
735
+ if groups == ''
736
+ current_groups_to_vals[0o100] = chmod_perm_num
737
+ current_groups_to_vals[0o10] = chmod_perm_num
738
+ current_groups_to_vals[0o1] = chmod_perm_num
739
+ else
740
+ # make sure there are no invalid flags in the groups
741
+ # and that we discard duplicates as chmod does
742
+ given_groups = groups.split('')
743
+ given_groups = given_groups.uniq
744
+ given_groups.each do |specific_group|
745
+ # ensure that the group is valid
746
+ unless valid_groups_to_numeric_vals.key? specific_group
747
+ raise ArgumentError, "Invalid `who' symbol in file mode: #{specific_group}"
748
+ end
749
+
750
+ # take the current chmod amt from earlier and assosciate that as the current chmod factor for the group
751
+ group_num = valid_groups_to_numeric_vals[specific_group]
752
+ current_groups_to_vals[group_num] = chmod_perm_num
753
+ end
754
+ end
755
+ end
756
+
757
+ # return an octal chmod value for the value
758
+ 0o100 * current_groups_to_vals[0o100] + 0o10 * current_groups_to_vals[0o10] + current_groups_to_vals[0o1]
759
+ end
760
+
761
+ private_class_method :convert_symbolic_chmod_to_absolute
762
+
675
763
  private
676
764
 
677
765
  def check_modes!
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '0.17.0'.freeze
4
+ VERSION = '0.18.0'.freeze
5
5
 
6
6
  def self.to_s
7
7
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-07-16 00:00:00.000000000 Z
15
+ date: 2018-07-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bump