class Pathutil

def safe_copy_directory(to, root: nil)

def safe_copy_directory(to, root: nil)
  if !in_path?(root)
    raise Errno::EPERM, "#{self} not in #{
      root
    }"
  else
    to.mkdir_p unless to.exist?
    children do |file|
      if !file.in_path?(root)
        raise Errno::EPERM, "#{file} not in #{
          root
        }"
      elsif file.file?
        FileUtils.cp(file, to, {
          :preserve => true
        })
      else
        path = file.realpath
        path.safe_copy(to.join(file.basename), {
          :root => root
        })
      end
    end
  end
end