Class: XcodeInstaller::Entry_

Inherits:
Object
  • Object
show all
Includes:
StreamUtils_
Defined in:
lib/xcode-installer/install.rb

Overview

:nodoc: internal use only

Constant Summary collapse

S_IF_DOOR =
0xD000

Instance Method Summary collapse

Constructor Details

#initialize(a, b = nil, deref = false) ⇒ Entry_

Returns a new instance of Entry_.



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/xcode-installer/install.rb', line 181

def initialize(a, b = nil, deref = false)
  @prefix = @rel = @path = nil
  if b
    @prefix = a
    @rel = b
  else
    @path = a
  end
  @deref = deref
  @stat = nil
  @lstat = nil
end

Instance Method Details

#blockdev?Boolean

Returns:

  • (Boolean)


242
243
244
245
# File 'lib/xcode-installer/install.rb', line 242

def blockdev?
  s = lstat!
  s and s.blockdev?
end

#chardev?Boolean

Returns:

  • (Boolean)


237
238
239
240
# File 'lib/xcode-installer/install.rb', line 237

def chardev?
  s = lstat!
  s and s.chardev?
end

#chmod(mode) ⇒ Object



308
309
310
311
312
313
314
# File 'lib/xcode-installer/install.rb', line 308

def chmod(mode)
  if symlink?
    File.lchmod mode, path() if have_lchmod?
  else
    File.chmod mode, path()
  end
end

#chown(uid, gid) ⇒ Object



316
317
318
319
320
321
322
# File 'lib/xcode-installer/install.rb', line 316

def chown(uid, gid)
  if symlink?
    File.lchown uid, gid, path() if have_lchown?
  else
    File.chown uid, gid, path()
  end
end

#copy(dest) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/xcode-installer/install.rb', line 324

def copy(dest)
  case
  when file?
    copy_file dest
  when directory?
    if !File.exist?(dest) and descendant_diretory?(dest, path)
      raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest]
    end
    begin
      Dir.mkdir dest
    rescue
      raise unless File.directory?(dest)
    end
  when symlink?
    File.symlink File.readlink(path()), dest
  when chardev?
    raise "cannot handle device file" unless File.respond_to?(:mknod)
    mknod dest, ?c, 0666, lstat().rdev
  when blockdev?
    raise "cannot handle device file" unless File.respond_to?(:mknod)
    mknod dest, ?b, 0666, lstat().rdev
  when socket?
    raise "cannot handle socket" unless File.respond_to?(:mknod)
    mknod dest, nil, lstat().mode, 0
  when pipe?
    raise "cannot handle FIFO" unless File.respond_to?(:mkfifo)
    mkfifo dest, 0666
  when door?
    raise "cannot handle door: #{path()}"
  else
    raise "unknown file type: #{path()}"
  end
end

#copy_file(dest) ⇒ Object



358
359
360
361
362
363
364
# File 'lib/xcode-installer/install.rb', line 358

def copy_file(dest)
  File.open(path()) do |s|
    File.open(dest, 'wb', s.stat.mode) do |f|
      IO.copy_stream(s, f)
    end
  end
end

#copy_metadata(path) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/xcode-installer/install.rb', line 366

def (path)
  st = lstat()
  File.utime st.atime, st.mtime, path
  begin
    File.chown st.uid, st.gid, path
  rescue Errno::EPERM
    # clear setuid/setgid
    File.chmod st.mode & 01777, path
  else
    File.chmod st.mode, path
  end
end

#dereference?Boolean

Returns:

  • (Boolean)


214
215
216
# File 'lib/xcode-installer/install.rb', line 214

def dereference?
  @deref
end

#directory?Boolean

Returns:

  • (Boolean)


227
228
229
230
# File 'lib/xcode-installer/install.rb', line 227

def directory?
  s = lstat!
  s and s.directory?
end

#door?Boolean

Returns:

  • (Boolean)


259
260
261
262
# File 'lib/xcode-installer/install.rb', line 259

def door?
  s = lstat!
  s and (s.mode & 0xF000 == S_IF_DOOR)
end

#entriesObject



264
265
266
267
268
269
270
# File 'lib/xcode-installer/install.rb', line 264

def entries
  opts = {}
  opts[:encoding] = ::Encoding::UTF_8 if fu_windows?
  Dir.entries(path(), opts)\
      .reject {|n| n == '.' or n == '..' }\
      .map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
end

#exist?Boolean

Returns:

  • (Boolean)


218
219
220
# File 'lib/xcode-installer/install.rb', line 218

def exist?
  lstat! ? true : false
end

#file?Boolean

Returns:

  • (Boolean)


222
223
224
225
# File 'lib/xcode-installer/install.rb', line 222

def file?
  s = lstat!
  s and s.file?
end

#inspectObject



194
195
196
# File 'lib/xcode-installer/install.rb', line 194

def inspect
  "\#<#{self.class} #{path()}>"
end

#lstatObject



294
295
296
297
298
299
300
# File 'lib/xcode-installer/install.rb', line 294

def lstat
  if dereference?
    @lstat ||= File.stat(path())
  else
    @lstat ||= File.lstat(path())
  end
end

#lstat!Object



302
303
304
305
306
# File 'lib/xcode-installer/install.rb', line 302

def lstat!
  lstat()
rescue SystemCallError
  nil
end

#pathObject



198
199
200
201
202
203
204
# File 'lib/xcode-installer/install.rb', line 198

def path
  if @path
    File.path(@path)
  else
    join(@prefix, @rel)
  end
end

#pipe?Boolean

Returns:

  • (Boolean)


252
253
254
255
# File 'lib/xcode-installer/install.rb', line 252

def pipe?
  s = lstat!
  s and s.pipe?
end

#platform_supportObject



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/xcode-installer/install.rb', line 399

def platform_support
  return yield unless fu_windows?
  first_time_p = true
  begin
    yield
  rescue Errno::ENOENT
    raise
  rescue => err
    if first_time_p
      first_time_p = false
      begin
        File.chmod 0700, path()   # Windows does not have symlink
        retry
      rescue SystemCallError
      end
    end
    raise err
  end
end

#postorder_traverse {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



429
430
431
432
433
434
435
436
437
438
# File 'lib/xcode-installer/install.rb', line 429

def postorder_traverse
  if directory?
    entries().each do |ent|
      ent.postorder_traverse do |e|
        yield e
      end
    end
  end
  yield self
end

#prefixObject



206
207
208
# File 'lib/xcode-installer/install.rb', line 206

def prefix
  @prefix || @path
end

#preorder_traverseObject Also known as: traverse



419
420
421
422
423
424
425
# File 'lib/xcode-installer/install.rb', line 419

def preorder_traverse
  stack = [self]
  while ent = stack.pop
    yield ent
    stack.concat ent.entries.reverse if ent.directory?
  end
end

#relObject



210
211
212
# File 'lib/xcode-installer/install.rb', line 210

def rel
  @rel
end

#removeObject



379
380
381
382
383
384
385
# File 'lib/xcode-installer/install.rb', line 379

def remove
  if directory?
    remove_dir1
  else
    remove_file
  end
end

#remove_dir1Object



387
388
389
390
391
# File 'lib/xcode-installer/install.rb', line 387

def remove_dir1
  platform_support {
    Dir.rmdir path().chomp(?/)
  }
end

#remove_fileObject



393
394
395
396
397
# File 'lib/xcode-installer/install.rb', line 393

def remove_file
  platform_support {
    File.unlink path
  }
end

#socket?Boolean

Returns:

  • (Boolean)


247
248
249
250
# File 'lib/xcode-installer/install.rb', line 247

def socket?
  s = lstat!
  s and s.socket?
end

#statObject



272
273
274
275
276
277
278
279
280
# File 'lib/xcode-installer/install.rb', line 272

def stat
  return @stat if @stat
  if lstat() and lstat().symlink?
    @stat = File.stat(path())
  else
    @stat = lstat()
  end
  @stat
end

#stat!Object



282
283
284
285
286
287
288
289
290
291
292
# File 'lib/xcode-installer/install.rb', line 282

def stat!
  return @stat if @stat
  if lstat! and lstat!.symlink?
    @stat = File.stat(path())
  else
    @stat = lstat!
  end
  @stat
rescue SystemCallError
  nil
end

#symlink?Boolean

Returns:

  • (Boolean)


232
233
234
235
# File 'lib/xcode-installer/install.rb', line 232

def symlink?
  s = lstat!
  s and s.symlink?
end