class Dle::DlFile::Generator

Public Class Methods

new(fs) click to toggle source
# File lib/dle/dl_file.rb, line 59
def initialize fs
  @fs = fs
end

Public Instance Methods

render() click to toggle source
# File lib/dle/dl_file.rb, line 63
def render
  # inode, mode, own/grp, size, file
  table = [[], [], [], [], []]
  @fs.index.each do |rpath, node|
    table[0] << node.inode
    table[1] << node.mode
    table[2] << node.owngrp
    table[3] << human_filesize(node.size)
    table[4] << node.relative_path
  end

  ([
    %{#},
    %{# - If you remove a line we just don't care!},
    %{# - If you add a line we just don't care!},
    %{# - If you change a path we will "mkdir -p" the destination and move the file/dir},
    %{# - If you change the owner we will "chown" the file/dir},
    %{# - If you change the mode we will "chmod" the file/dir},
    %{# - If you change the mode to "cp" and modify the path we will copy instead of moving/renaming},
    %{# - If you change the mode to "del" we will "rm" the file},
    %{# - If you change the mode to "delr" we will "rm" the file or directory},
    %{# - If you change the mode to "delf" or "delrf" we will "rm -f" the file or directory},
    %{# - We will apply changes in this order (inside-out):},
    %{#     - Ownership},
    %{#     - Permissions},
    %{#     - Rename/Move},
    %{#     - Copy},
    %{#     - Delete},
    %{#},
    %{# Gotchas:},
    %{#   - If you have "folder/subfolder/file" and want to rename "subfolder" to "dubfolder"},
    %{#     do it only in the specific node, don't change the path of "file"!},
    %{#   - If you want to copy a directory, only copy the directory node, not a file inside it.},
    %{#     Folders will be copied recursively.},
    %{#   - The script works with file IDs (IN column). That allows you to remove files in renamed},
    %{#     folders without adjusting paths. This is not a gotcha, it's a hint :)},
    %{#   - Note that indexing is quite fast but applying changes on a base directory with a lot},
    %{#     of files and directories may be slow since we fully reindex after each operation.},
    %{#     Maybe the mapping will keep track of changes in later updates so that this isn't necessary},
    %{# --------------------------------------------------},
    %{},
    %{<HD-BASE>#{@fs.base_dir}</HD-BASE>},
    %{<HD-DOTFILES>#{@fs.opts[:dotfiles]}</HD-DOTFILES>},
    %{},
  ] + render_table(table, ["IN", "Mode", "Owner", "Size", "File"])).map(&:strip).join("\n")
end