Skip to content

Commit

Permalink
Enhanced filter function (added ent argument)
Browse files Browse the repository at this point in the history
  • Loading branch information
kratz00 committed May 25, 2013
1 parent 9733497 commit 96cef20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 23 additions & 3 deletions docs.txt
Expand Up @@ -804,20 +804,40 @@ Here are the elements, and the attributes they can possess.

filter (no default, mustBeFunction)

This is a function that takes one argument, a string that represents the
path of a single file relative to the root of the installation destination.
This is a function that takes two arguments, a string that represents the
path of a single file relative to the root of the installation destination
and a table with additional information about the file.

The table has the following fields:

type (string)
The type of the file.
Valid types are "file", "dir", "symlink" and "unknown".

filesize (number)
The size of the file in bytes.

linkdest (string)
The destination of the symbolic link if the file is of type "symlink" otherwise it's nil.

filename (string)
The file name.

This function may return nil to choose not to install this file, which is
useful for culling files from an archive, or a string that represents a
new destination for the file, which is useful for renaming some files
on-the-fly:

filter = function(dest)
filter = function(dest, ent)
if string.match(dest, ".exe$") then
return nil -- skip Windows .exe files on Unix.
end
if dest == "SOMEFILE.TXT" then
return "somefile.txt" -- force this to lowercase.
end
if ent.type == "dir" then
return dest, "0755" -- make sure directories are created with the proper permission
end
return dest -- everything else can go through as-is.
end

Expand Down
2 changes: 1 addition & 1 deletion scripts/mojosetup_mainline.lua
Expand Up @@ -588,7 +588,7 @@ local function install_archive_entry(archive, ent, file, option)

if file.filter ~= nil then
local filterperms
dest, filterperms = file.filter(dest)
dest, filterperms = file.filter(dest, ent)
if filterperms ~= nil then
perms = filterperms
end
Expand Down

0 comments on commit 96cef20

Please sign in to comment.