Class: Archive::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-libarchive/entry.rb

Constant Summary collapse

S_IFMT =
0170000
S_IFSOCK =

socket

0140000
S_IFLNK =

symbolic link

0120000
S_IFREG =

regular file

0100000
S_IFBLK =

block device

0060000
S_IFDIR =

directory

0040000
S_IFCHR =

character device

0020000
S_IFIFO =

FIFO

0010000
SOCKET =

socket

0140000
0120000
FILE =

regular file

0100000
BLOCK_SPECIAL =

block device

0060000
DIRECTORY =

directory

0040000
CHARACTER_SPECIAL =

character device

0020000
FIFO =

FIFO

0010000

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry = nil, clone: false) ⇒ Entry

Returns a new instance of Entry.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ffi-libarchive/entry.rb', line 24

def initialize(entry = nil, clone: false)
  @entry_free = [true]
  if entry
    @entry = clone ? C.archive_entry_clone(entry) : entry
    yield self if block_given?
  else
    @entry = C.archive_entry_new
    raise Error, @entry unless @entry

    if block_given?
      result = yield self
      C.archive_entry_free(@entry)
      @entry = nil
      result
    else
      @entry_free[0] = false
      ObjectSpace.define_finalizer(self, Entry.finalizer(@entry, @entry_free))
    end
  end
end

Class Method Details

.finalizer(entry, entry_free) ⇒ Object



45
46
47
48
49
# File 'lib/ffi-libarchive/entry.rb', line 45

def self.finalizer(entry, entry_free)
  proc do |*_args|
    C.archive_entry_free(entry) unless entry_free[0]
  end
end

.from_pointer(entry, clone: false) ⇒ Object



20
21
22
# File 'lib/ffi-libarchive/entry.rb', line 20

def self.from_pointer(entry, clone: false)
  new entry, clone: clone
end

Instance Method Details

#atimeObject



67
68
69
# File 'lib/ffi-libarchive/entry.rb', line 67

def atime
  Time.at C.archive_entry_atime(entry)
end

#atime=(time) ⇒ Object



71
72
73
# File 'lib/ffi-libarchive/entry.rb', line 71

def atime=(time)
  set_atime time, 0
end

#atime_is_set?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/ffi-libarchive/entry.rb', line 79

def atime_is_set?
  C.archive_entry_atime_is_set(entry) != 0
end

#atime_nsecObject



83
84
85
# File 'lib/ffi-libarchive/entry.rb', line 83

def atime_nsec
  C.archive_entry_atime_nsec(entry)
end

#birthtimeObject



87
88
89
# File 'lib/ffi-libarchive/entry.rb', line 87

def birthtime
  Time.at C.archive_entry_birthtime(entry)
end

#birthtime=(time) ⇒ Object



91
92
93
# File 'lib/ffi-libarchive/entry.rb', line 91

def birthtime=(time)
  set_birthtime time, 0
end

#birthtime_is_set?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/ffi-libarchive/entry.rb', line 99

def birthtime_is_set?
  C.archive_entry_birthtime_is_set(entry) != 0
end

#birthtime_nsecObject



103
104
105
# File 'lib/ffi-libarchive/entry.rb', line 103

def birthtime_nsec
  C.archive_entry_birthtime_nsec(entry)
end

#block_special?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/ffi-libarchive/entry.rb', line 127

def block_special?
  C.archive_entry_filetype(entry) & S_IFMT == S_IFBLK
end

#character_special?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/ffi-libarchive/entry.rb', line 131

def character_special?
  C.archive_entry_filetype(entry) & S_IFMT == S_IFCHR
end

#closeObject



51
52
53
54
55
56
57
58
59
# File 'lib/ffi-libarchive/entry.rb', line 51

def close
  # TODO: do we need synchronization here?
  if @entry && !@entry_free[0]
    @entry_free[0] = true
    C.archive_entry_free(@entry)
  end
ensure
  @entry = nil
end

#copy_fflags_text(fflags_text) ⇒ Object



156
157
158
159
# File 'lib/ffi-libarchive/entry.rb', line 156

def copy_fflags_text(fflags_text)
  C.archive_entry_copy_fflags_text(entry, fflags_text)
  nil
end

#copy_gname(gname) ⇒ Object



161
162
163
164
# File 'lib/ffi-libarchive/entry.rb', line 161

def copy_gname(gname)
  C.archive_entry_copy_gname(entry, gname)
  nil
end


166
167
168
169
# File 'lib/ffi-libarchive/entry.rb', line 166

def copy_hardlink(lnk)
  C.archive_entry_copy_hardlink(entry, lnk)
  nil
end


171
172
173
174
# File 'lib/ffi-libarchive/entry.rb', line 171

def copy_link(lnk)
  C.archive_entry_copy_link(entry, lnk)
  nil
end

#copy_lstat(filename) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/ffi-libarchive/entry.rb', line 176

def copy_lstat(filename)
  # TODO: get this work without ffi-inliner
  begin
    require File.join(Archive::LIBPATH, "ffi-libarchive", "stat")
  rescue => e
    raise "ffi-inliner build for copy_stat failed:\n#{e}"
  end

  stat = Archive::Stat.ffi_libarchive_create_lstat(filename)
  raise Error, "Copy stat failed: #{Archive::Stat.ffi_error}" if stat.null?

  C.archive_entry_copy_stat(entry, stat)
ensure
  Archive::Stat.ffi_libarchive_free_stat(stat)
end

#copy_pathname(file_name) ⇒ Object



192
193
194
195
# File 'lib/ffi-libarchive/entry.rb', line 192

def copy_pathname(file_name)
  C.archive_entry_copy_pathname(entry, file_name)
  nil
end

#copy_sourcepath(path) ⇒ Object



197
198
199
200
# File 'lib/ffi-libarchive/entry.rb', line 197

def copy_sourcepath(path)
  C.archive_copy_sourcepath(entry, path)
  nil
end

#copy_stat(filename) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ffi-libarchive/entry.rb', line 202

def copy_stat(filename)
  # TODO: get this work without ffi-inliner
  begin
    require File.join(Archive::LIBPATH, "ffi-libarchive", "stat")
  rescue => e
    raise "ffi-inliner build for copy_stat failed:\n#{e}"
  end

  stat = Archive::Stat.ffi_libarchive_create_stat(filename)
  raise Error, "Copy stat failed: #{Archive::Stat.ffi_error}" if stat.null?

  C.archive_entry_copy_stat(entry, stat)
ensure
  Archive::Stat.ffi_libarchive_free_stat(stat)
end


218
219
220
221
# File 'lib/ffi-libarchive/entry.rb', line 218

def copy_symlink(slnk)
  C.archive_copy_symlink(entry, slnk)
  nil
end

#copy_uname(uname) ⇒ Object



223
224
225
226
# File 'lib/ffi-libarchive/entry.rb', line 223

def copy_uname(uname)
  C.archive_copy_uname(entry, uname)
  nil
end

#ctimeObject



107
108
109
# File 'lib/ffi-libarchive/entry.rb', line 107

def ctime
  Time.at C.archive_entry_ctime(entry)
end

#ctime=(time) ⇒ Object



111
112
113
# File 'lib/ffi-libarchive/entry.rb', line 111

def ctime=(time)
  set_ctime time, 0
end

#ctime_is_set?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/ffi-libarchive/entry.rb', line 119

def ctime_is_set?
  C.archive_entry_ctime_is_set(entry) != 0
end

#ctime_nsecObject



123
124
125
# File 'lib/ffi-libarchive/entry.rb', line 123

def ctime_nsec
  C.archive_entry_ctime_nsec(entry)
end

#devObject



228
229
230
# File 'lib/ffi-libarchive/entry.rb', line 228

def dev
  C.archive_entry_dev(entry)
end

#dev=(dev) ⇒ Object



232
233
234
# File 'lib/ffi-libarchive/entry.rb', line 232

def dev=(dev)
  C.archive_entry_set_dev(entry, dev)
end

#devmajorObject



236
237
238
# File 'lib/ffi-libarchive/entry.rb', line 236

def devmajor
  C.archive_entry_devmajor(entry)
end

#devmajor=(dev) ⇒ Object



240
241
242
# File 'lib/ffi-libarchive/entry.rb', line 240

def devmajor=(dev)
  C.archive_entry_set_devmajor(entry, dev)
end

#devminorObject



244
245
246
# File 'lib/ffi-libarchive/entry.rb', line 244

def devminor
  C.archive_entry_devminor(entry)
end

#devminor=(dev) ⇒ Object



248
249
250
# File 'lib/ffi-libarchive/entry.rb', line 248

def devminor=(dev)
  C.archive_entry_set_devminor(entry, dev)
end

#directory?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/ffi-libarchive/entry.rb', line 135

def directory?
  C.archive_entry_filetype(entry) & S_IFMT == S_IFDIR
end

#entryObject



61
62
63
64
65
# File 'lib/ffi-libarchive/entry.rb', line 61

def entry
  raise "No entry object" unless @entry

  @entry
end

#fflagsObject



252
253
254
255
256
257
# File 'lib/ffi-libarchive/entry.rb', line 252

def fflags
  set = FFI::MemoryPointer.new :long
  clear = FFI::MemoryPointer.new :long
  C.archive_entry_fflags(entry, set, clear)
  [set.get_long(0), clear.get_long(0)]
end

#fflags_textObject



259
260
261
# File 'lib/ffi-libarchive/entry.rb', line 259

def fflags_text
  C.archive_entry_fflags_text(entry)
end

#fifo?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/ffi-libarchive/entry.rb', line 139

def fifo?
  C.archive_entry_filetype(entry) & S_IFMT == S_IFIFO
end

#filetypeObject



263
264
265
# File 'lib/ffi-libarchive/entry.rb', line 263

def filetype
  C.archive_entry_filetype(entry)
end

#filetype=(type) ⇒ Object



267
268
269
270
# File 'lib/ffi-libarchive/entry.rb', line 267

def filetype=(type)
  type = Entry.const_get type.to_s.upcase.to_sym if type.is_a? Symbol
  C.archive_entry_set_filetype(entry, type)
end

#gidObject



272
273
274
# File 'lib/ffi-libarchive/entry.rb', line 272

def gid
  C.archive_entry_gid(entry)
end

#gid=(gid) ⇒ Object



276
277
278
# File 'lib/ffi-libarchive/entry.rb', line 276

def gid=(gid)
  C.archive_entry_set_gid(entry, gid)
end

#gnameObject



280
281
282
# File 'lib/ffi-libarchive/entry.rb', line 280

def gname
  C.archive_entry_gname(entry)
end

#gname=(gname) ⇒ Object



284
285
286
# File 'lib/ffi-libarchive/entry.rb', line 284

def gname=(gname)
  C.archive_entry_set_gname(entry, gname)
end


288
289
290
# File 'lib/ffi-libarchive/entry.rb', line 288

def hardlink
  C.archive_entry_hardlink(entry)
end

#hardlink=(lnk) ⇒ Object



292
293
294
# File 'lib/ffi-libarchive/entry.rb', line 292

def hardlink=(lnk)
  C.archive_entry_set_hardlink(entry, lnk)
end

#inoObject



296
297
298
# File 'lib/ffi-libarchive/entry.rb', line 296

def ino
  C.archive_entry_ino(entry)
end

#ino=(ino) ⇒ Object



300
301
302
# File 'lib/ffi-libarchive/entry.rb', line 300

def ino=(ino)
  C.archive_entry_set_ino(entry, ino)
end

#link=(lnk) ⇒ Object



304
305
306
# File 'lib/ffi-libarchive/entry.rb', line 304

def link=(lnk)
  C.archive_entry_set_link(entry, lnk)
end

#modeObject



308
309
310
# File 'lib/ffi-libarchive/entry.rb', line 308

def mode
  C.archive_entry_mode(entry)
end

#mode=(mode) ⇒ Object



312
313
314
# File 'lib/ffi-libarchive/entry.rb', line 312

def mode=(mode)
  C.archive_entry_set_mode(entry, mode)
end

#mtimeObject



316
317
318
# File 'lib/ffi-libarchive/entry.rb', line 316

def mtime
  Time.at C.archive_entry_mtime(entry)
end

#mtime=(time) ⇒ Object



320
321
322
# File 'lib/ffi-libarchive/entry.rb', line 320

def mtime=(time)
  set_mtime time, 0
end

#mtime_is_set?Boolean

Returns:

  • (Boolean)


328
329
330
# File 'lib/ffi-libarchive/entry.rb', line 328

def mtime_is_set?
  C.archive_entry_mtime_is_set(entry) != 0
end

#mtime_nsecObject



332
333
334
# File 'lib/ffi-libarchive/entry.rb', line 332

def mtime_nsec
  C.archive_entry_mtime_nsec(entry)
end


336
337
338
# File 'lib/ffi-libarchive/entry.rb', line 336

def nlink
  C.archive_entry_nlink(entry)
end

#nlink=(nlink) ⇒ Object



340
341
342
# File 'lib/ffi-libarchive/entry.rb', line 340

def nlink=(nlink)
  C.archive_entry_set_nlink(entry, nlink)
end

#pathnameObject



344
345
346
# File 'lib/ffi-libarchive/entry.rb', line 344

def pathname
  C.archive_entry_pathname(entry)
end

#pathname=(path) ⇒ Object



348
349
350
# File 'lib/ffi-libarchive/entry.rb', line 348

def pathname=(path)
  C.archive_entry_set_pathname(entry, path)
end

#perm=(perm) ⇒ Object



352
353
354
# File 'lib/ffi-libarchive/entry.rb', line 352

def perm=(perm)
  C.archive_entry_set_perm(entry, perm)
end

#rdevObject



356
357
358
# File 'lib/ffi-libarchive/entry.rb', line 356

def rdev
  C.archive_entry_rdev(entry)
end

#rdev=(dev) ⇒ Object



360
361
362
# File 'lib/ffi-libarchive/entry.rb', line 360

def rdev=(dev)
  C.archive_entry_set_rdev(entry, dev)
end

#rdevmajorObject



364
365
366
# File 'lib/ffi-libarchive/entry.rb', line 364

def rdevmajor
  C.archive_entry_rdevmajor(entry)
end

#rdevmajor=(dev) ⇒ Object



368
369
370
# File 'lib/ffi-libarchive/entry.rb', line 368

def rdevmajor=(dev)
  C.archive_entry_set_rdevmajor(entry, dev)
end

#rdevminorObject



372
373
374
# File 'lib/ffi-libarchive/entry.rb', line 372

def rdevminor
  C.archive_entry_rdevminor(entry)
end

#rdevminor=(dev) ⇒ Object



376
377
378
# File 'lib/ffi-libarchive/entry.rb', line 376

def rdevminor=(dev)
  C.archive_entry_set_rdevminor(entry, dev)
end

#regular?Boolean Also known as: file?

Returns:

  • (Boolean)


143
144
145
# File 'lib/ffi-libarchive/entry.rb', line 143

def regular?
  C.archive_entry_filetype(entry) & S_IFMT == S_IFREG
end

#set_atime(time, nsec) ⇒ Object



75
76
77
# File 'lib/ffi-libarchive/entry.rb', line 75

def set_atime(time, nsec)
  C.archive_entry_set_atime(entry, time.to_i, nsec)
end

#set_birthtime(time, nsec) ⇒ Object



95
96
97
# File 'lib/ffi-libarchive/entry.rb', line 95

def set_birthtime(time, nsec)
  C.archive_entry_set_birthtime(entry, time.to_i, nsec)
end

#set_ctime(time, nsec) ⇒ Object



115
116
117
# File 'lib/ffi-libarchive/entry.rb', line 115

def set_ctime(time, nsec)
  C.archive_entry_set_ctime(entry, time.to_i, nsec)
end

#set_fflags(set, clear) ⇒ Object



380
381
382
# File 'lib/ffi-libarchive/entry.rb', line 380

def set_fflags(set, clear)
  C.archive_entry_set_fflags(entry, set, clear)
end

#set_mtime(time, nsec) ⇒ Object



324
325
326
# File 'lib/ffi-libarchive/entry.rb', line 324

def set_mtime(time, nsec)
  C.archive_entry_set_mtime(entry, time.to_i, nsec)
end

#sizeObject



384
385
386
# File 'lib/ffi-libarchive/entry.rb', line 384

def size
  C.archive_entry_size(entry)
end

#size=(size) ⇒ Object



388
389
390
# File 'lib/ffi-libarchive/entry.rb', line 388

def size=(size)
  C.archive_entry_set_size(entry, size)
end

#size_is_set?Boolean

Returns:

  • (Boolean)


392
393
394
# File 'lib/ffi-libarchive/entry.rb', line 392

def size_is_set?
  C.archive_entry_size_is_set(entry) != 0
end

#socket?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/ffi-libarchive/entry.rb', line 148

def socket?
  C.archive_entry_filetype(entry) & S_IFMT == S_IFSOCK
end

#sourcepathObject



396
397
398
# File 'lib/ffi-libarchive/entry.rb', line 396

def sourcepath
  C.archive_entry_sourcepath(entry)
end

#strmodeObject



400
401
402
# File 'lib/ffi-libarchive/entry.rb', line 400

def strmode
  C.archive_entry_strmode(entry)
end

#symbolic_link?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/ffi-libarchive/entry.rb', line 152

def symbolic_link?
  C.archive_entry_filetype(entry) & S_IFMT == S_IFLNK
end


404
405
406
# File 'lib/ffi-libarchive/entry.rb', line 404

def symlink
  C.archive_entry_symlink(entry)
end

#symlink=(slnk) ⇒ Object



408
409
410
# File 'lib/ffi-libarchive/entry.rb', line 408

def symlink=(slnk)
  C.archive_entry_set_symlink(entry, slnk)
end

#uidObject



412
413
414
# File 'lib/ffi-libarchive/entry.rb', line 412

def uid
  C.archive_entry_uid(entry)
end

#uid=(uid) ⇒ Object



416
417
418
# File 'lib/ffi-libarchive/entry.rb', line 416

def uid=(uid)
  C.archive_entry_set_uid(entry, uid)
end

#unameObject



420
421
422
# File 'lib/ffi-libarchive/entry.rb', line 420

def uname
  C.archive_entry_uname(entry)
end

#uname=(uname) ⇒ Object



424
425
426
# File 'lib/ffi-libarchive/entry.rb', line 424

def uname=(uname)
  C.archive_entry_set_uname(entry, uname)
end

#unset_atimeObject



428
429
430
# File 'lib/ffi-libarchive/entry.rb', line 428

def unset_atime
  C.archive_entry_unset_atime(entry)
end

#unset_birthtimeObject



432
433
434
# File 'lib/ffi-libarchive/entry.rb', line 432

def unset_birthtime
  C.archive_entry_unset_birthtime(entry)
end

#unset_ctimeObject



436
437
438
# File 'lib/ffi-libarchive/entry.rb', line 436

def unset_ctime
  C.archive_entry_unset_ctime(entry)
end

#unset_mtimeObject



440
441
442
# File 'lib/ffi-libarchive/entry.rb', line 440

def unset_mtime
  C.archive_entry_unset_mtime(entry)
end

#unset_sizeObject



444
445
446
# File 'lib/ffi-libarchive/entry.rb', line 444

def unset_size
  C.archive_entry_unset_size(entry)
end

#xattr_add_entry(name, value) ⇒ Object



448
449
450
# File 'lib/ffi-libarchive/entry.rb', line 448

def xattr_add_entry(name, value)
  C.archive_entry_xattr_add_entry(entry, name, value, value.size)
end

#xattr_clearObject



452
453
454
# File 'lib/ffi-libarchive/entry.rb', line 452

def xattr_clear
  C.archive_entry_xattr_clear(entry)
end

#xattr_countObject



456
457
458
# File 'lib/ffi-libarchive/entry.rb', line 456

def xattr_count
  C.archive_entry_xattr_count(entry)
end

#xattr_nextObject



460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/ffi-libarchive/entry.rb', line 460

def xattr_next
  name = FFI::MemoryPointer.new :pointer
  value = FFI::MemoryPointer.new :pointer
  size = FFI::MemoryPointer.new :size_t
  if C.archive_entry_xattr_next(entry, name, value, size) != C::OK
    nil
  else
    # TODO: someday size.read_size_t could work
    [name.null? ? nil : name.read_string,
            value.null? ? nil : value.get_string(0, size.read_ulong)]
  end
end

#xattr_resetObject



473
474
475
# File 'lib/ffi-libarchive/entry.rb', line 473

def xattr_reset
  C.archive_entry_xattr_reset(entry)
end