fileutils 1.7.3 → 1.8.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fileutils.rb +57 -52
  3. metadata +4 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9187fa7b726decd18c3126b2ec86e2b4dcc9c867c523563b997708c6a3ef802
4
- data.tar.gz: 9b31af2775d26c335a6322a420d6fc248646e2989b563b6698fc4aee93f95863
3
+ metadata.gz: 86c6c5b356b1a4609616761dd686d3fef6611d3e60bb6cef6b44c624454a2e2f
4
+ data.tar.gz: ec91ec1155d38977abefbfa963d6c5bdc6ebadaf22481a70f6359a4e5a3a4b6d
5
5
  SHA512:
6
- metadata.gz: '0187dc049dcc1cf76967f1d3f2b436b34e3b16ad7cc5a6b03482be3937633dbd5822d3c4f1f4d34e959155efa250935d7c7f8de122ace2a1ccda47883dfdd2ef'
7
- data.tar.gz: 2381eef71dc0be7c3894e43947557ef56a3c4c4d9c5d12410ca9799ef48ec869340005eaeb7e7180f0af41fc909a1078bd934b3a9c8decf95e69d2acea0d0d63
6
+ metadata.gz: 14affe38fe72bee2de39d9cf4897361ab1fcfd47a8e25f9faae47f563f283491826525a170d01e86bb3423a17cd43477daeceb1ac6c64d6dff6483cab36da702
7
+ data.tar.gz: 174d36e824096f64e63db03c42631d0f3511cbdf48be425cf922ddbe711956404b1b39bc8d2f7d9241d218beba4c0fca7b40d9a5bbb15b29a7980db5db10cde2
data/lib/fileutils.rb CHANGED
@@ -181,7 +181,7 @@ end
181
181
  #
182
182
  module FileUtils
183
183
  # The version number.
184
- VERSION = "1.7.3"
184
+ VERSION = "1.8.0"
185
185
 
186
186
  def self.private_module_function(name) #:nodoc:
187
187
  module_function name
@@ -706,11 +706,12 @@ module FileUtils
706
706
  #
707
707
  def ln_s(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil)
708
708
  if relative
709
- return ln_sr(src, dest, force: force, noop: noop, verbose: verbose)
709
+ return ln_sr(src, dest, force: force, target_directory: target_directory, noop: noop, verbose: verbose)
710
710
  end
711
- fu_output_message "ln -s#{force ? 'f' : ''} #{[src,dest].flatten.join ' '}" if verbose
711
+ fu_output_message "ln -s#{force ? 'f' : ''}#{
712
+ target_directory ? '' : 'T'} #{[src,dest].flatten.join ' '}" if verbose
712
713
  return if noop
713
- fu_each_src_dest0(src, dest) do |s,d|
714
+ fu_each_src_dest0(src, dest, target_directory) do |s,d|
714
715
  remove_file d, true if force
715
716
  File.symlink s, d
716
717
  end
@@ -730,42 +731,37 @@ module FileUtils
730
731
  # Like FileUtils.ln_s, but create links relative to +dest+.
731
732
  #
732
733
  def ln_sr(src, dest, target_directory: true, force: nil, noop: nil, verbose: nil)
733
- options = "#{force ? 'f' : ''}#{target_directory ? '' : 'T'}"
734
- dest = File.path(dest)
735
- srcs = Array(src)
736
- link = proc do |s, target_dir_p = true|
737
- s = File.path(s)
738
- if target_dir_p
739
- d = File.join(destdirs = dest, File.basename(s))
734
+ cmd = "ln -s#{force ? 'f' : ''}#{target_directory ? '' : 'T'}" if verbose
735
+ fu_each_src_dest0(src, dest, target_directory) do |s,d|
736
+ if target_directory
737
+ parent = File.dirname(d)
738
+ destdirs = fu_split_path(parent)
739
+ real_ddirs = fu_split_path(File.realpath(parent))
740
740
  else
741
- destdirs = File.dirname(d = dest)
741
+ destdirs ||= fu_split_path(dest)
742
+ real_ddirs ||= fu_split_path(File.realdirpath(dest))
742
743
  end
743
- destdirs = fu_split_path(File.realpath(destdirs))
744
- if fu_starting_path?(s)
745
- srcdirs = fu_split_path((File.realdirpath(s) rescue File.expand_path(s)))
746
- base = fu_relative_components_from(srcdirs, destdirs)
747
- s = File.join(*base)
744
+ srcdirs = fu_split_path(s)
745
+ i = fu_common_components(srcdirs, destdirs)
746
+ n = destdirs.size - i
747
+ n -= 1 unless target_directory
748
+ link1 = fu_clean_components(*Array.new([n, 0].max, '..'), *srcdirs[i..-1])
749
+ begin
750
+ real_sdirs = fu_split_path(File.realdirpath(s)) rescue nil
751
+ rescue
748
752
  else
749
- srcdirs = fu_clean_components(*fu_split_path(s))
750
- base = fu_relative_components_from(fu_split_path(Dir.pwd), destdirs)
751
- while srcdirs.first&. == ".." and base.last&.!=("..") and !fu_starting_path?(base.last)
752
- srcdirs.shift
753
- base.pop
754
- end
755
- s = File.join(*base, *srcdirs)
753
+ i = fu_common_components(real_sdirs, real_ddirs)
754
+ n = real_ddirs.size - i
755
+ n -= 1 unless target_directory
756
+ link2 = fu_clean_components(*Array.new([n, 0].max, '..'), *real_sdirs[i..-1])
757
+ link1 = link2 if link1.size > link2.size
756
758
  end
757
- fu_output_message "ln -s#{options} #{s} #{d}" if verbose
759
+ s = File.join(link1)
760
+ fu_output_message [cmd, s, d].flatten.join(' ') if verbose
758
761
  next if noop
759
762
  remove_file d, true if force
760
763
  File.symlink s, d
761
764
  end
762
- case srcs.size
763
- when 0
764
- when 1
765
- link[srcs[0], target_directory && File.directory?(dest)]
766
- else
767
- srcs.each(&link)
768
- end
769
765
  end
770
766
  module_function :ln_sr
771
767
 
@@ -800,13 +796,13 @@ module FileUtils
800
796
  # File.file?('dest1/dir1/t2.txt') # => true
801
797
  # File.file?('dest1/dir1/t3.txt') # => true
802
798
  #
803
- # Keyword arguments:
799
+ # Optional arguments:
804
800
  #
805
- # - <tt>dereference_root: true</tt> - dereferences +src+ if it is a symbolic link.
806
- # - <tt>remove_destination: true</tt> - removes +dest+ before creating links.
801
+ # - +dereference_root+ - dereferences +src+ if it is a symbolic link (+false+ by default).
802
+ # - +remove_destination+ - removes +dest+ before creating links (+false+ by default).
807
803
  #
808
804
  # Raises an exception if +dest+ is the path to an existing file or directory
809
- # and keyword argument <tt>remove_destination: true</tt> is not given.
805
+ # and optional argument +remove_destination+ is not given.
810
806
  #
811
807
  # Related: FileUtils.ln (has different options).
812
808
  #
@@ -1029,12 +1025,12 @@ module FileUtils
1029
1025
  # directories, and symbolic links;
1030
1026
  # other file types (FIFO streams, device files, etc.) are not supported.
1031
1027
  #
1032
- # Keyword arguments:
1028
+ # Optional arguments:
1033
1029
  #
1034
- # - <tt>dereference_root: true</tt> - if +src+ is a symbolic link,
1035
- # follows the link.
1036
- # - <tt>preserve: true</tt> - preserves file times.
1037
- # - <tt>remove_destination: true</tt> - removes +dest+ before copying files.
1030
+ # - +dereference_root+ - if +src+ is a symbolic link,
1031
+ # follows the link (+false+ by default).
1032
+ # - +preserve+ - preserves file times (+false+ by default).
1033
+ # - +remove_destination+ - removes +dest+ before copying files (+false+ by default).
1038
1034
  #
1039
1035
  # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
1040
1036
  #
@@ -1065,12 +1061,12 @@ module FileUtils
1065
1061
  # FileUtils.copy_file('src0.txt', 'dest0.txt')
1066
1062
  # File.file?('dest0.txt') # => true
1067
1063
  #
1068
- # Keyword arguments:
1064
+ # Optional arguments:
1069
1065
  #
1070
- # - <tt>dereference: false</tt> - if +src+ is a symbolic link,
1071
- # does not follow the link.
1072
- # - <tt>preserve: true</tt> - preserves file times.
1073
- # - <tt>remove_destination: true</tt> - removes +dest+ before copying files.
1066
+ # - +dereference+ - if +src+ is a symbolic link,
1067
+ # follows the link (+true+ by default).
1068
+ # - +preserve+ - preserves file times (+false+ by default).
1069
+ # - +remove_destination+ - removes +dest+ before copying files (+false+ by default).
1074
1070
  #
1075
1071
  # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
1076
1072
  #
@@ -1491,7 +1487,8 @@ module FileUtils
1491
1487
  # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
1492
1488
  #
1493
1489
  def remove_dir(path, force = false)
1494
- remove_entry path, force # FIXME?? check if it is a directory
1490
+ raise Errno::ENOTDIR, path unless force or File.directory?(path)
1491
+ remove_entry path, force
1495
1492
  end
1496
1493
  module_function :remove_dir
1497
1494
 
@@ -2475,6 +2472,10 @@ module FileUtils
2475
2472
 
2476
2473
  def fu_each_src_dest0(src, dest, target_directory = true) #:nodoc:
2477
2474
  if tmp = Array.try_convert(src)
2475
+ unless target_directory or tmp.size <= 1
2476
+ tmp = tmp.map {|f| File.path(f)} # A workaround for RBS
2477
+ raise ArgumentError, "extra target #{tmp}"
2478
+ end
2478
2479
  tmp.each do |s|
2479
2480
  s = File.path(s)
2480
2481
  yield s, (target_directory ? File.join(dest, File.basename(s)) : dest)
@@ -2509,7 +2510,11 @@ module FileUtils
2509
2510
  path = File.path(path)
2510
2511
  list = []
2511
2512
  until (parent, base = File.split(path); parent == path or parent == ".")
2512
- list << base
2513
+ if base != '..' and list.last == '..' and !(fu_have_symlink? && File.symlink?(path))
2514
+ list.pop
2515
+ else
2516
+ list << base
2517
+ end
2513
2518
  path = parent
2514
2519
  end
2515
2520
  list << path
@@ -2517,14 +2522,14 @@ module FileUtils
2517
2522
  end
2518
2523
  private_module_function :fu_split_path
2519
2524
 
2520
- def fu_relative_components_from(target, base) #:nodoc:
2525
+ def fu_common_components(target, base) #:nodoc:
2521
2526
  i = 0
2522
2527
  while target[i]&.== base[i]
2523
2528
  i += 1
2524
2529
  end
2525
- Array.new(base.size-i, '..').concat(target[i..-1])
2530
+ i
2526
2531
  end
2527
- private_module_function :fu_relative_components_from
2532
+ private_module_function :fu_common_components
2528
2533
 
2529
2534
  def fu_clean_components(*comp) #:nodoc:
2530
2535
  comp.shift while comp.first == "."
@@ -2534,7 +2539,7 @@ module FileUtils
2534
2539
  while c = comp.shift
2535
2540
  if c == ".." and clean.last != ".." and !(fu_have_symlink? && File.symlink?(path))
2536
2541
  clean.pop
2537
- path.chomp!(%r((?<=\A|/)[^/]+/\z), "")
2542
+ path.sub!(%r((?<=\A|/)[^/]+/\z), "")
2538
2543
  else
2539
2544
  clean << c
2540
2545
  path << c << "/"
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fileutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Several file utility methods for copying, moving, removing, etc.
14
13
  email:
15
- -
14
+ -
16
15
  executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
@@ -29,7 +28,6 @@ licenses:
29
28
  - BSD-2-Clause
30
29
  metadata:
31
30
  source_code_uri: https://github.com/ruby/fileutils
32
- post_install_message:
33
31
  rdoc_options: []
34
32
  require_paths:
35
33
  - lib
@@ -44,8 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
42
  - !ruby/object:Gem::Version
45
43
  version: '0'
46
44
  requirements: []
47
- rubygems_version: 3.5.11
48
- signing_key:
45
+ rubygems_version: 3.6.9
49
46
  specification_version: 4
50
47
  summary: Several file utility methods for copying, moving, removing, etc.
51
48
  test_files: []