Created
January 24, 2022 01:06
-
-
Save ixti/8e883fdf3b3a26bdc46880f7d968888c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "pathname" | |
require "yaml" | |
filetypes = File.open("config/filetypes.yml", "r") { |io| YAML.safe_load(io) } | |
# core types will be processed manually | |
filetypes.delete("core") | |
noop = proc { |*| } | |
test_dir = Pathname.new("#{__dir__}/vivid-test-files").tap(&:mkdir) | |
generate = lambda do |o, path| | |
case o | |
when Hash | |
o.each { |k, v| generate.call(v, path.join(k)) } | |
when Array | |
path.mkpath | |
o.each do |file| | |
file = "example#{file}" if file.start_with?(".") | |
path.join(file).open("w", &noop) | |
end | |
else | |
raise "wat?" | |
end | |
end | |
generate.call(filetypes, test_dir) | |
core = test_dir.join("core").tap(&:mkdir) | |
support = test_dir.join(".support").tap(&:mkdir) | |
core.join("regular_file").open("w", &noop) | |
core.join("directory").mkdir | |
symlink_target = support.join("symlink").tap { |it| it.open("w", &noop) } | |
core.join("symlink").make_symlink(symlink_target) | |
hardlink_target = support.join("hardlink").tap { |it| it.open("w", &noop) } | |
core.join("hardlink-1").make_link(hardlink_target) | |
core.join("hardlink-2").make_link(hardlink_target) | |
# covers both missing_symlink_target (MISSING) and broken_symlink (ORPHAN) | |
core.join("broken_symlink_target").make_symlink(support.join("broken_symlink_target")) | |
core.join("setuid").tap { |it| it.open("w", &noop) }.chmod(4644) | |
core.join("setgid").tap { |it| it.open("w", &noop) }.chmod(2644) | |
core.join("other_writable").tap { |it| it.open("w", &noop) }.chmod(666) | |
core.join("sticky_other_writable").tap { |it| it.open("w", &noop) }.chmod(1666) | |
core.join("sticky").tap { |it| it.open("w", &noop) }.chmod(1644) | |
core.join("executable_file").tap { |it| it.open("w", &noop) }.chmod(755) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment