Class: Archive::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi_libarchive/entry.rb

Constant Summary collapse

S_IFMT =

region File-type Constants

0o170000
S_IFSOCK =

bits mask

0o140000
S_IFLNK =
0o120000
S_IFREG =
0o100000
S_IFBLK =
0o060000
S_IFDIR =
0o040000
S_IFCHR =
0o020000
S_IFIFO =
0o010000
SOCKET =
S_IFSOCK
S_IFLNK
FILE =

regular file

S_IFREG
BLOCK_DEVICE =

block special device

S_IFBLK
DIRECTORY =
S_IFDIR
CHARACTER_DEVICE =

character special device

S_IFCHR
FIFO =

named pipe (FIFO)

S_IFIFO

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry = nil) ⇒ Entry

Returns a new instance of Entry.

Parameters:

  • entry (FFI::Pointer) (defaults to: nil)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ffi_libarchive/entry.rb', line 37

def initialize(entry = nil)
  if entry
    @entry = entry
  else
    @entry = C.archive_entry_new
    raise Error, 'No entry object' unless @entry
  end

  if block_given?
    begin
      yield self
    ensure
      close
    end
  else
    ObjectSpace.define_finalizer(self, method(:close).to_proc)
  end
end

Instance Attribute Details

#entryFFI::Pointer (readonly)

Returns:

  • (FFI::Pointer)


64
65
66
# File 'lib/ffi_libarchive/entry.rb', line 64

def entry
  @entry
end

Class Method Details

.file_typesObject



24
25
26
# File 'lib/ffi_libarchive/entry.rb', line 24

def self.file_types
  @file_types ||= Hash[constants.reject { |k| k =~ /^S_/ }.map { |k| [k.downcase, const_get(k)] }]
end

.from_pointer(entry) ⇒ Entry

Parameters:

  • (FFI::Pointer)

Returns:



32
33
34
# File 'lib/ffi_libarchive/entry.rb', line 32

def self.from_pointer(entry)
  new entry
end

Instance Method Details

#atimeTime

Returns:

  • (Time)


110
# File 'lib/ffi_libarchive/entry.rb', line 110

attach_attribute :archive_entry_atime, post: proc_time_at

#atime_is_set?Boolean

Returns:

  • (Boolean)


121
# File 'lib/ffi_libarchive/entry.rb', line 121

attach_attribute :archive_entry_atime_is_set, post: proc_is_nonzero

#atime_nsecInteger

Returns :long.

Returns:

  • (Integer)

    :long



125
# File 'lib/ffi_libarchive/entry.rb', line 125

attach_attribute :archive_entry_atime_nsec

#birthtimeTime

Returns:

  • (Time)


134
# File 'lib/ffi_libarchive/entry.rb', line 134

attach_attribute :archive_entry_birthtime, post: proc_time_at

#birthtime_is_set?Boolean

Returns:

  • (Boolean)


145
# File 'lib/ffi_libarchive/entry.rb', line 145

attach_attribute :archive_entry_birthtime_is_set, post: proc_is_nonzero

#birthtime_nsecInteger

Returns :long.

Returns:

  • (Integer)

    :long



149
# File 'lib/ffi_libarchive/entry.rb', line 149

attach_attribute :archive_entry_birthtime_nsec

#block_device?Boolean Also known as: block_special?

Returns:

  • (Boolean)


206
207
208
# File 'lib/ffi_libarchive/entry.rb', line 206

file_types.each do |k, v|
  define_method("#{k}?".to_sym) { (filetype & S_IFMT) == v }
end

#character_device?Boolean Also known as: character_special?

Returns:

  • (Boolean)


206
207
208
# File 'lib/ffi_libarchive/entry.rb', line 206

file_types.each do |k, v|
  define_method("#{k}?".to_sym) { (filetype & S_IFMT) == v }
end

#closeObject



56
57
58
59
60
61
# File 'lib/ffi_libarchive/entry.rb', line 56

def close
  # TODO: do we need synchronization here?
  C.archive_entry_free(@entry) if @entry
ensure
  @entry = nil
end

#copy_fflags_text(fflags_text) ⇒ String Also known as: fflags_text=

Returns Invalid token string, or NULL if success.

Parameters:

  • fflags_text (String)

Returns:

  • (String)

    Invalid token string, or NULL if success



310
# File 'lib/ffi_libarchive/entry.rb', line 310

attach_attribute :archive_entry_copy_fflags_text

#copy_gname(gname) ⇒ Object

Parameters:

  • gname (String)


334
# File 'lib/ffi_libarchive/entry.rb', line 334

attach_attribute :archive_entry_copy_gname

Parameters:

  • lnk (String)


349
# File 'lib/ffi_libarchive/entry.rb', line 349

attach_attribute :archive_entry_copy_hardlink

Parameters:

  • lnk (String)


357
# File 'lib/ffi_libarchive/entry.rb', line 357

attach_attribute :archive_entry_copy_link

#copy_lstat(filename) ⇒ Object

Parameters:

  • filename (String, FFI::Pointer)


228
229
230
# File 'lib/ffi_libarchive/entry.rb', line 228

def copy_lstat(filename)
  copy_stat_from(filename.is_a?(String) ? File.lstat(filename) : filename)
end

#copy_pathname(file_name) ⇒ Object

Parameters:

  • file_name (String)


456
# File 'lib/ffi_libarchive/entry.rb', line 456

attach_attribute :archive_entry_copy_pathname

#copy_sourcepath(path) ⇒ Object Also known as: sourcepath=

Parameters:

  • path (String)


510
# File 'lib/ffi_libarchive/entry.rb', line 510

attach_attribute :archive_entry_copy_sourcepath

#copy_stat(filename) ⇒ Object

Parameters:

  • filename (String, FFI::Pointer)


233
234
235
# File 'lib/ffi_libarchive/entry.rb', line 233

def copy_stat(filename)
  copy_stat_from(filename.is_a?(String) ? File.stat(filename) : filename)
end

#copy_stat_from(stat) ⇒ Object

Parameters:

  • stat (FFI::Pointer, File::Stat)


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/ffi_libarchive/entry.rb', line 239

def copy_stat_from(stat)
  if stat.respond_to?(:null?) && !stat.null?
    C.archive_entry_copy_stat(entry, stat)

  elsif stat.is_a?(File::Stat)
    %w[dev gid uid ino nlink rdev size mode].each do |fn|
      # @type [Integer]
      f = stat.send(fn)
      send "#{fn}=", f if f
    end

    %w[atime ctime mtime birthtime].each do |fn|
      # @type [Time]
      f = stat.respond_to?(fn) ? stat.send(fn) : nil
      send "set_#{fn}", f, f.tv_nsec if f
    end
  else
    raise ArgumentError, "Copying stat for #{stat.class} is not supported"
  end
end

Parameters:

  • lnk (String)


369
# File 'lib/ffi_libarchive/entry.rb', line 369

attach_attribute :archive_entry_copy_symlink

#copy_uname(uname) ⇒ Object

Parameters:

  • uname (String)


533
# File 'lib/ffi_libarchive/entry.rb', line 533

attach_attribute :archive_entry_copy_uname

#ctimeTime

Returns:

  • (Time)


158
# File 'lib/ffi_libarchive/entry.rb', line 158

attach_attribute :archive_entry_ctime, post: proc_time_at

#ctime_is_set?Boolean

Returns:

  • (Boolean)


169
# File 'lib/ffi_libarchive/entry.rb', line 169

attach_attribute :archive_entry_ctime_is_set, post: proc_is_nonzero

#ctime_nsecInteger

Returns :long.

Returns:

  • (Integer)

    :long



173
# File 'lib/ffi_libarchive/entry.rb', line 173

attach_attribute :archive_entry_ctime_nsec

#devInteger

Returns :dev_t.

Returns:

  • (Integer)

    :dev_t



265
# File 'lib/ffi_libarchive/entry.rb', line 265

attach_attribute :archive_entry_dev

#dev=(dev) ⇒ Object

Parameters:

  • dev (Integer)


269
# File 'lib/ffi_libarchive/entry.rb', line 269

attach_attribute :archive_entry_set_dev, name: 'dev='

#devmajorInteger

Returns :dev_t.

Returns:

  • (Integer)

    :dev_t



273
# File 'lib/ffi_libarchive/entry.rb', line 273

attach_attribute :archive_entry_devmajor

#devmajor=(dev) ⇒ Object

Parameters:

  • dev (Integer)


277
# File 'lib/ffi_libarchive/entry.rb', line 277

attach_attribute :archive_entry_set_devmajor, name: 'devmajor='

#devminorInteger

Returns :dev_t.

Returns:

  • (Integer)

    :dev_t



281
# File 'lib/ffi_libarchive/entry.rb', line 281

attach_attribute :archive_entry_devminor

#devminor=(dev) ⇒ Object

Parameters:

  • dev (Integer)


285
# File 'lib/ffi_libarchive/entry.rb', line 285

attach_attribute :archive_entry_set_devminor, name: 'devminor='

#directory?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/ffi_libarchive/entry.rb', line 206

file_types.each do |k, v|
  define_method("#{k}?".to_sym) { (filetype & S_IFMT) == v }
end

#fflagsArray<Integer>

region File flags/attributes (see #lsattr)

Returns:

  • (Array<Integer>)

    of [:set, :clear]



290
291
292
293
294
295
296
# File 'lib/ffi_libarchive/entry.rb', line 290

def fflags
  set   = FFI::MemoryPointer.new :ulong
  clear = FFI::MemoryPointer.new :ulong
  C.archive_entry_fflags(entry, set, clear)

  [set.get_ulong(0), clear.get_ulong(0)]
end

#fflags_textString

Returns:

  • (String)


305
# File 'lib/ffi_libarchive/entry.rb', line 305

attach_attribute :archive_entry_fflags_text

#fifo?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/ffi_libarchive/entry.rb', line 206

file_types.each do |k, v|
  define_method("#{k}?".to_sym) { (filetype & S_IFMT) == v }
end

#file?Boolean Also known as: regular?

Returns:

  • (Boolean)


206
207
208
# File 'lib/ffi_libarchive/entry.rb', line 206

file_types.each do |k, v|
  define_method("#{k}?".to_sym) { (filetype & S_IFMT) == v }
end

#filetypeInteger

Returns :mode_t.

Returns:

  • (Integer)

    :mode_t



183
# File 'lib/ffi_libarchive/entry.rb', line 183

attach_attribute :archive_entry_filetype

#filetype=(type) ⇒ Object

Parameters:

  • type (Integer, #to_s)


187
188
189
190
# File 'lib/ffi_libarchive/entry.rb', line 187

attach_attribute(
  :archive_entry_set_filetype,
  name: 'filetype=', pre: ->(args) { args.map! { |t| t.is_a?(Integer) ? t : const_get(t.to_s.upcase) } }
)

#filetype_sSymbol

Returns:

  • (Symbol)


215
216
217
# File 'lib/ffi_libarchive/entry.rb', line 215

def filetype_s
  self.class.file_types.key(filetype & S_IFMT)
end

#gidInteger

Returns :int64_t.

Returns:

  • (Integer)

    :int64_t



318
# File 'lib/ffi_libarchive/entry.rb', line 318

attach_attribute :archive_entry_gid

#gid=(gid) ⇒ Object

Parameters:

  • gid (Integer)


322
# File 'lib/ffi_libarchive/entry.rb', line 322

attach_attribute :archive_entry_set_gid, name: 'gid='

#gnameString

Returns:

  • (String)


326
# File 'lib/ffi_libarchive/entry.rb', line 326

attach_attribute :archive_entry_gname

#gname=(gname) ⇒ Object

Parameters:

  • gname (String)


330
# File 'lib/ffi_libarchive/entry.rb', line 330

attach_attribute :archive_entry_set_gname, name: 'gname='

Returns:

  • (String)


341
# File 'lib/ffi_libarchive/entry.rb', line 341

attach_attribute :archive_entry_hardlink

#hardlink=(lnk) ⇒ Object

Parameters:

  • lnk (String)


345
# File 'lib/ffi_libarchive/entry.rb', line 345

attach_attribute :archive_entry_set_hardlink, name: 'hardlink='

#inoInteger

Returns :int64_t of inode number.

Returns:

  • (Integer)

    :int64_t of inode number



375
# File 'lib/ffi_libarchive/entry.rb', line 375

attach_attribute :archive_entry_ino

#ino=(ino) ⇒ Object

Parameters:

  • ino (String)

    inode number



379
# File 'lib/ffi_libarchive/entry.rb', line 379

attach_attribute :archive_entry_set_ino, name: 'ino='

#link=(lnk) ⇒ Object

Parameters:

  • lnk (String)


353
# File 'lib/ffi_libarchive/entry.rb', line 353

attach_attribute :archive_entry_set_link, name: 'link='

#modeInteger

Returns :mode_t.

Returns:

  • (Integer)

    :mode_t



385
# File 'lib/ffi_libarchive/entry.rb', line 385

attach_attribute :archive_entry_mode

#mode=(mode) ⇒ Object

Parameters:

  • mode (Integer)

    File protection (see #filetype)



389
# File 'lib/ffi_libarchive/entry.rb', line 389

attach_attribute :archive_entry_set_mode, name: 'mode='

#mtimeTime

Returns:

  • (Time)


408
# File 'lib/ffi_libarchive/entry.rb', line 408

attach_attribute :archive_entry_mtime, post: proc_time_at

#mtime_is_set?Boolean

Returns:

  • (Boolean)


419
# File 'lib/ffi_libarchive/entry.rb', line 419

attach_attribute :archive_entry_mtime_is_set, post: proc_is_nonzero

#mtime_nsecInteger

Returns :long.

Returns:

  • (Integer)

    :long



423
# File 'lib/ffi_libarchive/entry.rb', line 423

attach_attribute :archive_entry_mtime_nsec

Returns :uint.

Returns:

  • (Integer)

    :uint



431
# File 'lib/ffi_libarchive/entry.rb', line 431

attach_attribute :archive_entry_nlink

#nlink=(nlink) ⇒ Object

Parameters:

  • nlink (Integer)

    Number of hard links / files in a directory



435
# File 'lib/ffi_libarchive/entry.rb', line 435

attach_attribute :archive_entry_set_nlink, name: 'nlink='

#pathnameString

Returns:

  • (String)


440
# File 'lib/ffi_libarchive/entry.rb', line 440

attach_attribute :archive_entry_pathname

#pathname=(path) ⇒ Object

Parameters:

  • path (String)


444
# File 'lib/ffi_libarchive/entry.rb', line 444

attach_attribute :archive_entry_set_pathname, name: 'pathname='

#pathname_wString

Returns:

  • (String)


448
# File 'lib/ffi_libarchive/entry.rb', line 448

attach_attribute :archive_entry_pathname_w, maybe: true, post: proc_read_wide_string

#pathname_w=(path) ⇒ Object

Parameters:

  • path (String)


452
# File 'lib/ffi_libarchive/entry.rb', line 452

attach_attribute :archive_entry_copy_pathname_w, name: 'pathname_w=', pre: proc_string_arg_to_wide

#permInteger

Returns :mode_t.

Returns:

  • (Integer)

    :mode_t



393
# File 'lib/ffi_libarchive/entry.rb', line 393

attach_attribute :archive_entry_perm

#perm=(perm) ⇒ Object

Parameters:

  • perm (Integer)

    of :mode_t



397
# File 'lib/ffi_libarchive/entry.rb', line 397

attach_attribute :archive_entry_set_perm, name: 'perm='

#rdevInteger

Returns :dev_t.

Returns:

  • (Integer)

    :dev_t



462
# File 'lib/ffi_libarchive/entry.rb', line 462

attach_attribute :archive_entry_rdev

#rdev=(dev) ⇒ Object

Parameters:

  • dev (Integer)


466
# File 'lib/ffi_libarchive/entry.rb', line 466

attach_attribute :archive_entry_set_rdev, name: 'rdev='

#rdevmajorInteger

Returns :dev_t.

Returns:

  • (Integer)

    :dev_t



470
# File 'lib/ffi_libarchive/entry.rb', line 470

attach_attribute :archive_entry_rdevmajor

#rdevmajor=(dev) ⇒ Object

Parameters:

  • dev (Integer)


474
# File 'lib/ffi_libarchive/entry.rb', line 474

attach_attribute :archive_entry_set_rdevmajor, name: 'rdevmajor='

#rdevminorInteger

Returns :dev_t.

Returns:

  • (Integer)

    :dev_t



478
# File 'lib/ffi_libarchive/entry.rb', line 478

attach_attribute :archive_entry_rdevminor

#rdevminor=(dev) ⇒ Object

Parameters:

  • dev (Integer)


482
# File 'lib/ffi_libarchive/entry.rb', line 482

attach_attribute :archive_entry_set_rdevminor, name: 'rdevminor='

#set_atime(time, nsec = 0) ⇒ Object Also known as: atime=

Parameters:

  • time (Time, #to_i)
  • nsec (Integer, #to_i) (defaults to: 0)


115
# File 'lib/ffi_libarchive/entry.rb', line 115

attach_attribute :archive_entry_set_atime, pre: proc_2_args_to_i

#set_birthtime(time, nsec = 0) ⇒ Object Also known as: birthtime=

Parameters:

  • time (Time, #to_i)
  • nsec (Integer, #to_i) (defaults to: 0)


139
# File 'lib/ffi_libarchive/entry.rb', line 139

attach_attribute :archive_entry_set_birthtime, pre: proc_2_args_to_i

#set_ctime(time, nsec = 0) ⇒ Object Also known as: ctime=

Parameters:

  • time (Time, #to_i)
  • nsec (Integer, #to_i) (defaults to: 0)


163
# File 'lib/ffi_libarchive/entry.rb', line 163

attach_attribute :archive_entry_set_ctime, pre: proc_2_args_to_i

#set_fflags(set, clear) ⇒ Object

Parameters:

  • set (Integer)
  • clear (Integer)


301
# File 'lib/ffi_libarchive/entry.rb', line 301

attach_attribute :archive_entry_set_fflags

#set_mtime(time, nsec = 0) ⇒ Object Also known as: mtime=

Parameters:

  • time (Time, #to_i)
  • nsec (Integer, #to_i) (defaults to: 0)


413
# File 'lib/ffi_libarchive/entry.rb', line 413

attach_attribute :archive_entry_set_mtime, pre: proc_2_args_to_i

#sizeInteger

Returns :int64_t.

Returns:

  • (Integer)

    :int64_t



489
# File 'lib/ffi_libarchive/entry.rb', line 489

attach_attribute :archive_entry_size

#size=(size) ⇒ Object

Parameters:

  • size (Integer)


493
# File 'lib/ffi_libarchive/entry.rb', line 493

attach_attribute :archive_entry_set_size, name: 'size='

#size_is_set?Boolean

Returns:

  • (Boolean)


497
# File 'lib/ffi_libarchive/entry.rb', line 497

attach_attribute :archive_entry_size_is_set, post: proc_is_nonzero

#socket?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/ffi_libarchive/entry.rb', line 206

file_types.each do |k, v|
  define_method("#{k}?".to_sym) { (filetype & S_IFMT) == v }
end

#sourcepathString

Returns:

  • (String)


506
# File 'lib/ffi_libarchive/entry.rb', line 506

attach_attribute :archive_entry_sourcepath

#statFFI::Pointer

Returns:

  • (FFI::Pointer)


225
# File 'lib/ffi_libarchive/entry.rb', line 225

attach_attribute :archive_entry_stat

#strmodeString

Returns:

  • (String)


401
# File 'lib/ffi_libarchive/entry.rb', line 401

attach_attribute :archive_entry_strmode

#symbolic_link?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/ffi_libarchive/entry.rb', line 206

file_types.each do |k, v|
  define_method("#{k}?".to_sym) { (filetype & S_IFMT) == v }
end

Returns:

  • (String)


361
# File 'lib/ffi_libarchive/entry.rb', line 361

attach_attribute :archive_entry_symlink

#symlink=(lnk) ⇒ Object

Parameters:

  • lnk (String)


365
# File 'lib/ffi_libarchive/entry.rb', line 365

attach_attribute :archive_entry_set_symlink, name: 'symlink='

#uidInteger

Returns :int64_t.

Returns:

  • (Integer)

    :int64_t



517
# File 'lib/ffi_libarchive/entry.rb', line 517

attach_attribute :archive_entry_uid

#uid=(uid) ⇒ Object

Parameters:

  • uid (Integer)


521
# File 'lib/ffi_libarchive/entry.rb', line 521

attach_attribute :archive_entry_set_uid, name: 'uid='

#unameString

Returns:

  • (String)


525
# File 'lib/ffi_libarchive/entry.rb', line 525

attach_attribute :archive_entry_uname

#uname=(uname) ⇒ Object

Parameters:

  • uname (String)


529
# File 'lib/ffi_libarchive/entry.rb', line 529

attach_attribute :archive_entry_set_uname, name: 'uname='

#unset_atimeObject



128
# File 'lib/ffi_libarchive/entry.rb', line 128

attach_attribute :archive_entry_unset_atime

#unset_birthtimeObject



152
# File 'lib/ffi_libarchive/entry.rb', line 152

attach_attribute :archive_entry_unset_birthtime

#unset_ctimeObject



176
# File 'lib/ffi_libarchive/entry.rb', line 176

attach_attribute :archive_entry_unset_ctime

#unset_mtimeObject



426
# File 'lib/ffi_libarchive/entry.rb', line 426

attach_attribute :archive_entry_unset_mtime

#unset_sizeObject



500
# File 'lib/ffi_libarchive/entry.rb', line 500

attach_attribute :archive_entry_unset_size

#xattr_add_entry(name, value) ⇒ Object

Parameters:

  • name (String)
  • value (String)

Raises:

  • (ArgumentError)


540
541
542
543
544
# File 'lib/ffi_libarchive/entry.rb', line 540

def xattr_add_entry(name, value)
  raise ArgumentError, 'value is not a String' unless value.is_a?(String)

  C.archive_entry_xattr_add_entry(entry, name, Utils.get_memory_ptr(value), value.bytesize)
end

#xattr_clearObject



547
# File 'lib/ffi_libarchive/entry.rb', line 547

attach_attribute :archive_entry_xattr_clear

#xattr_countInteger

Returns:

  • (Integer)


551
# File 'lib/ffi_libarchive/entry.rb', line 551

attach_attribute :archive_entry_xattr_count

#xattr_nextArray<String>

Returns of [:name, :value].

Returns:

  • (Array<String>)

    of [:name, :value]



554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/ffi_libarchive/entry.rb', line 554

def xattr_next
  name  = FFI::MemoryPointer.new :pointer
  value = FFI::MemoryPointer.new :pointer
  size  = FFI::MemoryPointer.new :size_t
  return nil if C.archive_entry_xattr_next(entry, name, value, size) != C::OK

  name  = name.get_pointer(0) unless name.null?
  value = value.get_pointer(0) unless value.null?
  # Someday size.get(:size_t) could work
  [
    name.null? ? nil : name.get_string(0),
    value.null? ? nil : value.get_bytes(0, size.send("get_uint#{FFI.type_size(:size_t) * 8}", 0))
  ]
end

#xattr_resetInteger

Returns:

  • (Integer)


571
# File 'lib/ffi_libarchive/entry.rb', line 571

attach_attribute :archive_entry_xattr_reset