Cross package maker. DEB/RPM generation or conversion. Derived from jordansissel/fpm.

⌈⌋ ⎇ branch:  cross package maker


Check-in [8f076a2392]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Consolidate filename+dirname lowercasing, switch to regex (FNM_EXTGLOB absent in Ruby 1.9.x).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8f076a2392d3e63370caec87810a0476eef573a9
User & Date: mario 2014-12-30 12:34:23
Context
2014-12-30
12:35
Permit staging_path rebuilding (set to nil on .cleanup), and provide :mkdir and :mkdirname creation in staging_path(subdir). check-in: 11502e1206 user: mario tags: trunk
12:34
Consolidate filename+dirname lowercasing, switch to regex (FNM_EXTGLOB absent in Ruby 1.9.x). check-in: 8f076a2392 user: mario tags: trunk
2014-12-29
17:15
Add trivial approach to filename lowercasing. (Useful for .phar packages.) check-in: 6c3683bcaa user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/fpm/package/filter_lcase.rb.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

# api: fpm
# title: Lowercase filenames
# description: Changes filenames and directories to lowercase in the packaging process
# type: rewrite
# category: filter
# version: 0.1
# license: MITL
#
# Lowercase input filenames and directories. Filenames according to
# specified extension list, or all files per `=*` parameter.
#
# Usage:
#  -u lcase=c:php:rb






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14

# api: fpm
# title: Lowercase filenames
# description: Changes filenames and directories to lowercase in the packaging process
# type: rewrite
# category: filter
# version: 0.2
# license: MITL
#
# Lowercase input filenames and directories. Filenames according to
# specified extension list, or all files per `=*` parameter.
#
# Usage:
#  -u lcase=c:php:rb
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52


53
54
55


56

57







58
59


60
61
62

63
64
65

66
67
68
69
70
71
72


# rename uppercase filenames and directories
class FPM::Package::Filter_lcase < FPM::Package

  # rewrite filenames
  def update(opts)

    # prepare file search  
    if opts.empty?
      exts = ".none#only~dirs"
    elsif opts.include? "*"
      exts = "*"
    else
      exts = "*.{#{opts.join(',')}}"
    end
  
    # work within collected file tree
    ::Dir.chdir(staging_path) do

      # directories first, otherwise paths are more likely to become invalid
      files = ::Dir.glob("**/*")
      files.select { |fn| File.directory?(fn) }.each do
        #@bug this doesn't guarantee we're getting upper level dirs first
        #  actually should merge dir and file rewrites again
        #  (better yet, just use `find | sed | mv`
        |dir|
        lcase = dir.downcase
        if dir.include? "/"


          dir = File.join(File.dirname(lcase), File.basename(dir))
        end
        unless dir == lcase


          p "#{dir} != #{lcase}"

          FileUtils.mv(dir, lcase)







        end
      end



      # files thereafter
      ::Dir.glob("**/#{exts}").each do

        |fn|
        lcase = fn.downcase
        # lowercase directories in either case

        FileUtils.mv(fn, fn.downcase) unless fn == lcase
        p "#{fn} -> #{lcase}"
      end

    end # .chdir
  end # def update
end







<
|

<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
>
>
|
|
|
>
>
|
>
|
>
>
>
>
>
>
>


>
>

<
<
>
|
|
<
>
|
<
|
|
|
|
|
24
25
26
27
28
29
30

31
32


33















34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56


57
58
59

60
61

62
63
64
65
66


# rename uppercase filenames and directories
class FPM::Package::Filter_lcase < FPM::Package

  # rewrite filenames
  def update(opts)

    # prepare file search pattern
    if opts.empty?


      exts = /^\.$/















    elsif opts.include? "*"
      exts = //
    else
      exts = /^ .+ \. (?: #{opts.join('|')} ) $/ix
    end
    # traverse directory tree
    walk(staging_path, exts)
  end # def update

    # Level-wise trough directories, so no further need to care about already lowercased dirnames
  def walk(dir, exts)
    ::Dir.chdir(dir) do
      ::Dir.glob("*").each do
        |fn|
        if File.directory?(fn)
          walk(lcase(fn), exts)
        elsif File.file?(fn)
          lcase(fn) if fn =~ exts
        end
      end
    end
  end # walk



  # Only rename to lowercase if filename isn't already
  def lcase(fn)
    down = fn.downcase

    unless fn == down
      FileUtils.mv(fn, down)

    end
    return down
  end # lcase

end # class