Class: Qrpm::FileNode

Inherits:
HashNode show all
Defined in:
lib/qrpm/node.rb

Overview

A file. Always an element of a DirectoryNode object

A file is a hash with an integer key and with the following expressions as members:

file        Source file. The source file path is prefixed with $srcdir if
            defined. May be nil
name        Basename of the destination file. This defaults to the
            basename of the source file/symlink/reflink. The full path of
            the destination file is computed by prefixing the path of the
            parent directory
reflink     Path on the target filesystem to the source of the reflink
            (hard-link). May be nil
symlink     Path on the target filesystem to the source of the symlink.
            May be nil
perm        Permissions of the target file in chmod(1) octal or rwx
            notation. May be nil

Exactly one of ‘file’, ‘symlink’, and ‘reflink’ must be defined. ‘perm’ can’t be used together with ‘symlink’ or ‘reflink’

When interpolated the following methods are defined on a FileNode:

srcpath     Path to source file
dstpath     Path to destination file
dstname     Basename of destination file
reflink     Path to source link
symlink     Path to source link
perm        Permissions

Instance Attribute Summary collapse

Attributes inherited from Node

#expr, #name, #parent, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HashNode

#dump, #exprs

Methods inherited from ContainerNode

#exprs, #values, #variables

Methods inherited from Node

#class_name, #dot, #dump, #inspect, #interpolated?, #traverse, #variables

Constructor Details

#initialize(parent, name) ⇒ FileNode

Returns a new instance of FileNode.



283
284
285
286
287
# File 'lib/qrpm/node.rb', line 283

def initialize(parent, name)
  constrain parent, DirectoryNode
  constrain name, Integer
  super
end

Instance Attribute Details

#dstnameObject (readonly)

Destination file name



263
264
265
# File 'lib/qrpm/node.rb', line 263

def dstname
  @dstname
end

#dstpathObject (readonly)

Destination file path



260
261
262
# File 'lib/qrpm/node.rb', line 260

def dstpath
  @dstpath
end

#permObject (readonly)

Permissions of destination file. Perm is always a string



272
273
274
# File 'lib/qrpm/node.rb', line 272

def perm
  @perm
end

Hard-link file



266
267
268
# File 'lib/qrpm/node.rb', line 266

def reflink
  @reflink
end

#srcpathObject (readonly)

Source file. This is the relative path to the file in the build directory except for link files. Link files have a path on the target filesystem as path. It is the interpolated value of #expr



257
258
259
# File 'lib/qrpm/node.rb', line 257

def srcpath
  @srcpath
end

Symbolic link file



269
270
271
# File 'lib/qrpm/node.rb', line 269

def symlink
  @symlink
end

Class Method Details

.make(parent, arg) ⇒ Object

:call-seq:

FileNode.make(directory_node, filename)
FileNode.make(directory_node, hash)

Shorthand for creating file object



306
307
308
309
310
311
# File 'lib/qrpm/node.rb', line 306

def self.make(parent, arg)
  file = FileNode.new(parent, parent.size)
  hash = arg.is_a?(String) ? { "file" => arg } : arg
  hash.each { |k,v| ValueNode.new(file, k.to_s, Fragment::Fragment.parse(v)) }
  file
end

Instance Method Details

#directoryObject

Directory



275
# File 'lib/qrpm/node.rb', line 275

def directory = parent.directory

#dstObject

Name of destination. Returns the QRPM source expression or the interpolated result if the FileNode object has been interpolated. Used by Qrpm#dump



327
328
329
330
331
332
333
# File 'lib/qrpm/node.rb', line 327

def dst
  if expr["name"]
    interpolated? ? expr["name"].value : expr["name"].expr.source
  else
    File.basename(src)
  end
end

#file?Boolean

Query methods

Returns:

  • (Boolean)


278
# File 'lib/qrpm/node.rb', line 278

def file? = !link?

#interpolate(dict) ⇒ Object



289
290
291
292
293
294
295
296
297
298
299
# File 'lib/qrpm/node.rb', line 289

def interpolate(dict)
  super
  exprs.each { |e| e.interpolate(dict) }
  @srcpath = value[%w(file symlink reflink).find { |k| expr.key?(k) }].value
  @dstname = value["name"]&.value || File.basename(srcpath)
  @dstpath = "#{parent.directory}/#{@dstname}"
  @reflink = value["reflink"]&.value
  @symlink = value["symlink"]&.value
  @perm = value["perm"]&.value
  self
end

#link?Boolean

Returns:

  • (Boolean)


279
# File 'lib/qrpm/node.rb', line 279

def link? = symlink? || reflink?

#reflink?Boolean

Returns:

  • (Boolean)


280
# File 'lib/qrpm/node.rb', line 280

def reflink? = @expr.key?("reflink")

#signatureObject

Signature. Used in tests



314
# File 'lib/qrpm/node.rb', line 314

def signature = "FileNode(#{name},#{expr["file"].source})"

#srcObject

Path to source file. Returns the QRPM source expression or the interpolated result if the FileNode object has been interpolated. Used by Qrpm#dump



319
320
321
322
# File 'lib/qrpm/node.rb', line 319

def src
  e = expr["file"] || expr["reflink"] || expr["symlink"]
  interpolated? ? e.value : e.source
end

#symlink?Boolean

Returns:

  • (Boolean)


281
# File 'lib/qrpm/node.rb', line 281

def symlink? = @expr.key?("symlink")