rubysl-fileutils 2.0.2 → 2.0.3

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
  SHA1:
3
- metadata.gz: d761ddc43ef0525749a55c8d760a8b2ebed0f1b5
4
- data.tar.gz: eca038ad3c96269f4dcdd58e91ce614fbeb9310b
3
+ metadata.gz: d8fcbfc22d0164b564987124819d534da344d327
4
+ data.tar.gz: f60ec059b021ff8f344e5551f11a07bc0cc87daf
5
5
  SHA512:
6
- metadata.gz: a22182bdb72d35084cb676442e59b0fa0f42d3c29ac756e05063cf2fbe956912cc73187e7eb802d8fd4f05dbc4579387d038c4cd0196759978c5451e5ebb14bc
7
- data.tar.gz: 17907ff1ad7d1bb4c23150543a4bbf6531ed83802fe765c9f8be6c6565a1a00ccb1c36f30443f9d307ea73f0456fe6d9a35eb8e28b94fc15dcb3209611d85cae
6
+ metadata.gz: 42022a36e7987cf88ad2aa5991b5d4f581c9cdb823bfe76d9e6175b3f7d9c9ae19aee01ca5872204e3e0967aecc96177ed2fd4efe3ffb4f2ffedb428d604fb5d
7
+ data.tar.gz: 5837d545eb8563cd58cf55b367dc8fab70621ddedaa6eea055cd982b2c05ead348b8f70b5fc0502f19744e7321d825e635382e8d2133a0ceb331f1da8e1b3fb4
@@ -1,6 +1,14 @@
1
1
  language: ruby
2
2
  env:
3
3
  - RUBYLIB=lib
4
- script: bundle exec mspec spec
4
+ - RUBYLIB=
5
+ script: mspec spec
5
6
  rvm:
6
- - rbx-nightly-19mode
7
+ - 2.0.0
8
+ - rbx-2.1.1
9
+ matrix:
10
+ exclude:
11
+ - rvm: 2.0.0
12
+ env: RUBYLIB=lib
13
+ - rvm: rbx-2.1.1
14
+ env: RUBYLIB=
@@ -118,7 +118,7 @@ module FileUtils
118
118
  # FileUtils.cd('/') do # chdir
119
119
  # [...] # do something
120
120
  # end # return to original directory
121
- #
121
+ #
122
122
  def cd(dir, options = {}, &block) # :yield: dir
123
123
  fu_check_options options, OPT_TABLE['cd']
124
124
  fu_output_message "cd #{dir}" if options[:verbose]
@@ -142,9 +142,7 @@ module FileUtils
142
142
  # FileUtils.uptodate?('hello.o', %w(hello.c hello.h)) or \
143
143
  # system 'make hello.o'
144
144
  #
145
- def uptodate?(new, old_list, options = nil)
146
- raise ArgumentError, 'uptodate? does not accept any option' if options
147
-
145
+ def uptodate?(new, old_list)
148
146
  return false unless File.exist?(new)
149
147
  new_time = File.mtime(new)
150
148
  old_list.each do |old|
@@ -156,6 +154,11 @@ module FileUtils
156
154
  end
157
155
  module_function :uptodate?
158
156
 
157
+ def remove_tailing_slash(dir)
158
+ dir == '/' ? dir : dir.chomp(?/)
159
+ end
160
+ private_module_function :remove_tailing_slash
161
+
159
162
  #
160
163
  # Options: mode noop verbose
161
164
  #
@@ -202,7 +205,7 @@ module FileUtils
202
205
  fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
203
206
  return *list if options[:noop]
204
207
 
205
- list.map {|path| path.chomp(?/) }.each do |path|
208
+ list.map {|path| remove_tailing_slash(path)}.each do |path|
206
209
  # optimize for the most common case
207
210
  begin
208
211
  fu_mkdir path, options[:mode]
@@ -239,7 +242,7 @@ module FileUtils
239
242
  OPT_TABLE['makedirs'] = [:mode, :noop, :verbose]
240
243
 
241
244
  def fu_mkdir(path, mode) #:nodoc:
242
- path = path.chomp(?/)
245
+ path = remove_tailing_slash(path)
243
246
  if mode
244
247
  Dir.mkdir path, mode
245
248
  File.chmod mode, path
@@ -267,9 +270,10 @@ module FileUtils
267
270
  return if options[:noop]
268
271
  list.each do |dir|
269
272
  begin
270
- Dir.rmdir(dir = dir.chomp(?/))
273
+ Dir.rmdir(dir = remove_tailing_slash(dir))
271
274
  if parents
272
275
  until (parent = File.dirname(dir)) == '.' or parent == dir
276
+ dir = parent
273
277
  Dir.rmdir(dir)
274
278
  end
275
279
  end
@@ -363,7 +367,7 @@ module FileUtils
363
367
  # Options: noop verbose
364
368
  #
365
369
  # Same as
366
- # #ln_s(src, dest, :force)
370
+ # #ln_s(src, dest, :force => true)
367
371
  #
368
372
  def ln_sf(src, dest, options = {})
369
373
  fu_check_options options, OPT_TABLE['ln_sf']
@@ -413,7 +417,7 @@ module FileUtils
413
417
  #
414
418
  # +src+ can be a list of files.
415
419
  #
416
- # # Installing ruby library "mylib" under the site_ruby
420
+ # # Installing Ruby library "mylib" under the site_ruby
417
421
  # FileUtils.rm_r site_ruby + '/mylib', :force
418
422
  # FileUtils.cp_r 'lib/', site_ruby + '/mylib'
419
423
  #
@@ -424,7 +428,7 @@ module FileUtils
424
428
  # # If you want to copy all contents of a directory instead of the
425
429
  # # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
426
430
  # # use following code.
427
- # FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes src/dest,
431
+ # FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes dest/src,
428
432
  # # but this doesn't.
429
433
  #
430
434
  def cp_r(src, dest, options = {})
@@ -459,12 +463,14 @@ module FileUtils
459
463
  # If +remove_destination+ is true, this method removes each destination file before copy.
460
464
  #
461
465
  def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
462
- Entry_.new(src, nil, dereference_root).traverse do |ent|
466
+ Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent|
463
467
  destent = Entry_.new(dest, ent.rel, false)
464
468
  File.unlink destent.path if remove_destination && File.file?(destent.path)
465
469
  ent.copy destent.path
470
+ end, proc do |ent|
471
+ destent = Entry_.new(dest, ent.rel, false)
466
472
  ent.copy_metadata destent.path if preserve
467
- end
473
+ end)
468
474
  end
469
475
  module_function :copy_entry
470
476
 
@@ -747,7 +753,7 @@ module FileUtils
747
753
  File.symlink nil, nil
748
754
  rescue NotImplementedError
749
755
  return false
750
- rescue
756
+ rescue TypeError
751
757
  return true
752
758
  end
753
759
  private_module_function :fu_have_symlink?
@@ -823,16 +829,13 @@ module FileUtils
823
829
  #
824
830
  def compare_stream(a, b)
825
831
  bsize = fu_stream_blksize(a, b)
826
- sa = sb = nil
827
- while sa == sb
828
- sa = a.read(bsize)
829
- sb = b.read(bsize)
830
- unless sa and sb
831
- if sa.nil? and sb.nil?
832
- return true
833
- end
834
- end
835
- end
832
+ sa = ""
833
+ sb = ""
834
+ begin
835
+ a.read(bsize, sa)
836
+ b.read(bsize, sb)
837
+ return true if sa.empty? && sb.empty?
838
+ end while sa == sb
836
839
  false
837
840
  end
838
841
  module_function :compare_stream
@@ -865,62 +868,78 @@ module FileUtils
865
868
  OPT_TABLE['install'] = [:mode, :preserve, :noop, :verbose]
866
869
 
867
870
  def user_mask(target) #:nodoc:
868
- mask = 0
869
- target.each_byte do |byte_chr|
870
- case byte_chr.chr
871
- when "u"
872
- mask |= 04700
873
- when "g"
874
- mask |= 02070
875
- when "o"
876
- mask |= 01007
877
- when "a"
878
- mask |= 07777
871
+ target.each_char.inject(0) do |mask, chr|
872
+ case chr
873
+ when "u"
874
+ mask | 04700
875
+ when "g"
876
+ mask | 02070
877
+ when "o"
878
+ mask | 01007
879
+ when "a"
880
+ mask | 07777
881
+ else
882
+ raise ArgumentError, "invalid `who' symbol in file mode: #{chr}"
879
883
  end
880
884
  end
881
- mask
882
885
  end
883
886
  private_module_function :user_mask
884
887
 
885
- def mode_mask(mode, path) #:nodoc:
886
- mask = 0
887
- mode.each_byte do |byte_chr|
888
- case byte_chr.chr
889
- when "r"
890
- mask |= 0444
891
- when "w"
892
- mask |= 0222
893
- when "x"
894
- mask |= 0111
895
- when "X"
896
- mask |= 0111 if FileTest::directory? path
897
- when "s"
898
- mask |= 06000
899
- when "t"
900
- mask |= 01000
901
- end
888
+ def apply_mask(mode, user_mask, op, mode_mask)
889
+ case op
890
+ when '='
891
+ (mode & ~user_mask) | (user_mask & mode_mask)
892
+ when '+'
893
+ mode | (user_mask & mode_mask)
894
+ when '-'
895
+ mode & ~(user_mask & mode_mask)
902
896
  end
903
- mask
904
897
  end
905
- private_module_function :mode_mask
898
+ private_module_function :apply_mask
906
899
 
907
- def symbolic_modes_to_i(modes, path) #:nodoc:
908
- current_mode = (File.stat(path).mode & 07777)
909
- modes.split(/,/).inject(0) do |mode, mode_sym|
910
- mode_sym = "a#{mode_sym}" if mode_sym =~ %r!^[+-=]!
911
- target, mode = mode_sym.split %r![+-=]!
900
+ def symbolic_modes_to_i(mode_sym, path) #:nodoc:
901
+ mode_sym.split(/,/).inject(File.stat(path).mode & 07777) do |current_mode, clause|
902
+ target, *actions = clause.split(/([=+-])/)
903
+ raise ArgumentError, "invalid file mode: #{mode_sym}" if actions.empty?
904
+ target = 'a' if target.empty?
912
905
  user_mask = user_mask(target)
913
- mode_mask = mode_mask(mode ? mode : "", path)
914
-
915
- case mode_sym
916
- when /=/
917
- current_mode &= ~(user_mask)
918
- current_mode |= user_mask & mode_mask
919
- when /\+/
920
- current_mode |= user_mask & mode_mask
921
- when /-/
922
- current_mode &= ~(user_mask & mode_mask)
906
+ actions.each_slice(2) do |op, perm|
907
+ need_apply = op == '='
908
+ mode_mask = (perm || '').each_char.inject(0) do |mask, chr|
909
+ case chr
910
+ when "r"
911
+ mask | 0444
912
+ when "w"
913
+ mask | 0222
914
+ when "x"
915
+ mask | 0111
916
+ when "X"
917
+ if FileTest.directory? path
918
+ mask | 0111
919
+ else
920
+ mask
921
+ end
922
+ when "s"
923
+ mask | 06000
924
+ when "t"
925
+ mask | 01000
926
+ when "u", "g", "o"
927
+ if mask.nonzero?
928
+ current_mode = apply_mask(current_mode, user_mask, op, mask)
929
+ end
930
+ need_apply = false
931
+ copy_mask = user_mask(chr)
932
+ (current_mode & copy_mask) / (copy_mask & 0111) * (user_mask & 0111)
933
+ else
934
+ raise ArgumentError, "invalid `perm' symbol in file mode: #{chr}"
935
+ end
936
+ end
937
+
938
+ if mode_mask.nonzero? || need_apply
939
+ current_mode = apply_mask(current_mode, user_mask, op, mode_mask)
940
+ end
923
941
  end
942
+ current_mode
924
943
  end
925
944
  end
926
945
  private_module_function :symbolic_modes_to_i
@@ -930,6 +949,11 @@ module FileUtils
930
949
  end
931
950
  private_module_function :fu_mode
932
951
 
952
+ def mode_to_s(mode) #:nodoc:
953
+ mode.is_a?(String) ? mode : "%o" % mode
954
+ end
955
+ private_module_function :mode_to_s
956
+
933
957
  #
934
958
  # Options: noop verbose
935
959
  #
@@ -948,23 +972,25 @@ module FileUtils
948
972
  # FileUtils.chmod "u=wr,go=rr", %w(my.rb your.rb his.rb her.rb)
949
973
  # FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', :verbose => true
950
974
  #
951
- # "a" is user, group, other mask.
952
- # "u" is user's mask.
953
- # "g" is group's mask.
954
- # "o" is other's mask.
955
- # "w" is write permission.
956
- # "r" is read permission.
957
- # "x" is execute permission.
958
- # "s" is uid, gid.
959
- # "t" is sticky bit.
960
- # "+" is added to a class given the specified mode.
961
- # "-" Is removed from a given class given mode.
962
- # "=" Is the exact nature of the class will be given a specified mode.
975
+ # "a" :: is user, group, other mask.
976
+ # "u" :: is user's mask.
977
+ # "g" :: is group's mask.
978
+ # "o" :: is other's mask.
979
+ # "w" :: is write permission.
980
+ # "r" :: is read permission.
981
+ # "x" :: is execute permission.
982
+ # "X" ::
983
+ # is execute permission for directories only, must be used in conjunction with "+"
984
+ # "s" :: is uid, gid.
985
+ # "t" :: is sticky bit.
986
+ # "+" :: is added to a class given the specified mode.
987
+ # "-" :: Is removed from a given class given mode.
988
+ # "=" :: Is the exact nature of the class will be given a specified mode.
963
989
 
964
990
  def chmod(mode, list, options = {})
965
991
  fu_check_options options, OPT_TABLE['chmod']
966
992
  list = fu_list(list)
967
- fu_output_message sprintf('chmod %o %s', mode, list.join(' ')) if options[:verbose]
993
+ fu_output_message sprintf('chmod %s %s', mode_to_s(mode), list.join(' ')) if options[:verbose]
968
994
  return if options[:noop]
969
995
  list.each do |path|
970
996
  Entry_.new(path).chmod(fu_mode(mode, path))
@@ -986,9 +1012,9 @@ module FileUtils
986
1012
  def chmod_R(mode, list, options = {})
987
1013
  fu_check_options options, OPT_TABLE['chmod_R']
988
1014
  list = fu_list(list)
989
- fu_output_message sprintf('chmod -R%s %o %s',
1015
+ fu_output_message sprintf('chmod -R%s %s %s',
990
1016
  (options[:force] ? 'f' : ''),
991
- mode, list.join(' ')) if options[:verbose]
1017
+ mode_to_s(mode), list.join(' ')) if options[:verbose]
992
1018
  return if options[:noop]
993
1019
  list.each do |root|
994
1020
  Entry_.new(root).traverse do |ent|
@@ -1019,8 +1045,8 @@ module FileUtils
1019
1045
  def chown(user, group, list, options = {})
1020
1046
  fu_check_options options, OPT_TABLE['chown']
1021
1047
  list = fu_list(list)
1022
- fu_output_message sprintf('chown %s%s',
1023
- [user,group].compact.join(':') + ' ',
1048
+ fu_output_message sprintf('chown %s %s',
1049
+ (group ? "#{user}:#{group}" : user || ':'),
1024
1050
  list.join(' ')) if options[:verbose]
1025
1051
  return if options[:noop]
1026
1052
  uid = fu_get_uid(user)
@@ -1048,14 +1074,13 @@ module FileUtils
1048
1074
  def chown_R(user, group, list, options = {})
1049
1075
  fu_check_options options, OPT_TABLE['chown_R']
1050
1076
  list = fu_list(list)
1051
- fu_output_message sprintf('chown -R%s %s%s',
1077
+ fu_output_message sprintf('chown -R%s %s %s',
1052
1078
  (options[:force] ? 'f' : ''),
1053
- [user,group].compact.join(':') + ' ',
1079
+ (group ? "#{user}:#{group}" : user || ':'),
1054
1080
  list.join(' ')) if options[:verbose]
1055
1081
  return if options[:noop]
1056
1082
  uid = fu_get_uid(user)
1057
1083
  gid = fu_get_gid(group)
1058
- return unless uid or gid
1059
1084
  list.each do |root|
1060
1085
  Entry_.new(root).traverse do |ent|
1061
1086
  begin
@@ -1376,14 +1401,37 @@ module FileUtils
1376
1401
 
1377
1402
  def copy_metadata(path)
1378
1403
  st = lstat()
1379
- File.utime st.atime, st.mtime, path
1404
+ if !st.symlink?
1405
+ File.utime st.atime, st.mtime, path
1406
+ end
1380
1407
  begin
1381
- File.chown st.uid, st.gid, path
1408
+ if st.symlink?
1409
+ begin
1410
+ File.lchown st.uid, st.gid, path
1411
+ rescue NotImplementedError
1412
+ end
1413
+ else
1414
+ File.chown st.uid, st.gid, path
1415
+ end
1382
1416
  rescue Errno::EPERM
1383
1417
  # clear setuid/setgid
1384
- File.chmod st.mode & 01777, path
1418
+ if st.symlink?
1419
+ begin
1420
+ File.lchmod st.mode & 01777, path
1421
+ rescue NotImplementedError
1422
+ end
1423
+ else
1424
+ File.chmod st.mode & 01777, path
1425
+ end
1385
1426
  else
1386
- File.chmod st.mode, path
1427
+ if st.symlink?
1428
+ begin
1429
+ File.lchmod st.mode, path
1430
+ rescue NotImplementedError
1431
+ end
1432
+ else
1433
+ File.chmod st.mode, path
1434
+ end
1387
1435
  end
1388
1436
  end
1389
1437
 
@@ -1448,6 +1496,16 @@ module FileUtils
1448
1496
  yield self
1449
1497
  end
1450
1498
 
1499
+ def wrap_traverse(pre, post)
1500
+ pre.call self
1501
+ if directory?
1502
+ entries.each do |ent|
1503
+ ent.wrap_traverse pre, post
1504
+ end
1505
+ end
1506
+ post.call self
1507
+ end
1508
+
1451
1509
  private
1452
1510
 
1453
1511
  $fileutils_rb_have_lchmod = nil
@@ -1,5 +1,5 @@
1
1
  module RubySL
2
2
  module FileUtils
3
- VERSION = "2.0.2"
3
+ VERSION = "2.0.3"
4
4
  end
5
5
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "mspec", "~> 1.5"
24
+ spec.add_development_dependency "rubysl-prettyprint", "~> 2.0"
24
25
  end
metadata CHANGED
@@ -1,57 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysl-fileutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Shirai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2013-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubysl-prettyprint
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
55
69
  description: Ruby standard library fileutils.
56
70
  email:
57
71
  - brixen@gmail.com
@@ -59,8 +73,8 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
- - .gitignore
63
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".travis.yml"
64
78
  - Gemfile
65
79
  - LICENSE
66
80
  - README.md
@@ -80,12 +94,12 @@ require_paths:
80
94
  - lib
81
95
  required_ruby_version: !ruby/object:Gem::Requirement
82
96
  requirements:
83
- - - ~>
97
+ - - "~>"
84
98
  - !ruby/object:Gem::Version
85
99
  version: '2.0'
86
100
  required_rubygems_version: !ruby/object:Gem::Requirement
87
101
  requirements:
88
- - - '>='
102
+ - - ">="
89
103
  - !ruby/object:Gem::Version
90
104
  version: '0'
91
105
  requirements: []