Class: XcodeInstaller::Entry_
- Inherits:
-
Object
- Object
- XcodeInstaller::Entry_
- 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
- #blockdev? ⇒ Boolean
- #chardev? ⇒ Boolean
- #chmod(mode) ⇒ Object
- #chown(uid, gid) ⇒ Object
- #copy(dest) ⇒ Object
- #copy_file(dest) ⇒ Object
- #copy_metadata(path) ⇒ Object
- #dereference? ⇒ Boolean
- #directory? ⇒ Boolean
- #door? ⇒ Boolean
- #entries ⇒ Object
- #exist? ⇒ Boolean
- #file? ⇒ Boolean
-
#initialize(a, b = nil, deref = false) ⇒ Entry_
constructor
A new instance of Entry_.
- #inspect ⇒ Object
- #lstat ⇒ Object
- #lstat! ⇒ Object
- #path ⇒ Object
- #pipe? ⇒ Boolean
- #platform_support ⇒ Object
- #postorder_traverse {|_self| ... } ⇒ Object
- #prefix ⇒ Object
- #preorder_traverse ⇒ Object (also: #traverse)
- #rel ⇒ Object
- #remove ⇒ Object
- #remove_dir1 ⇒ Object
- #remove_file ⇒ Object
- #socket? ⇒ Boolean
- #stat ⇒ Object
- #stat! ⇒ Object
- #symlink? ⇒ Boolean
Constructor Details
#initialize(a, b = nil, deref = false) ⇒ Entry_
Returns a new instance of Entry_.
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/xcode-installer/install.rb', line 215 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
276 277 278 279 |
# File 'lib/xcode-installer/install.rb', line 276 def blockdev? s = lstat! s and s.blockdev? end |
#chardev? ⇒ Boolean
271 272 273 274 |
# File 'lib/xcode-installer/install.rb', line 271 def chardev? s = lstat! s and s.chardev? end |
#chmod(mode) ⇒ Object
342 343 344 345 346 347 348 |
# File 'lib/xcode-installer/install.rb', line 342 def chmod(mode) if symlink? File.lchmod mode, path() if have_lchmod? else File.chmod mode, path() end end |
#chown(uid, gid) ⇒ Object
350 351 352 353 354 355 356 |
# File 'lib/xcode-installer/install.rb', line 350 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
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/xcode-installer/install.rb', line 358 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
392 393 394 395 396 397 398 |
# File 'lib/xcode-installer/install.rb', line 392 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
400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/xcode-installer/install.rb', line 400 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
248 249 250 |
# File 'lib/xcode-installer/install.rb', line 248 def dereference? @deref end |
#directory? ⇒ Boolean
261 262 263 264 |
# File 'lib/xcode-installer/install.rb', line 261 def directory? s = lstat! s and s.directory? end |
#door? ⇒ Boolean
293 294 295 296 |
# File 'lib/xcode-installer/install.rb', line 293 def door? s = lstat! s and (s.mode & 0xF000 == S_IF_DOOR) end |
#entries ⇒ Object
298 299 300 301 302 303 304 |
# File 'lib/xcode-installer/install.rb', line 298 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
252 253 254 |
# File 'lib/xcode-installer/install.rb', line 252 def exist? lstat! ? true : false end |
#file? ⇒ Boolean
256 257 258 259 |
# File 'lib/xcode-installer/install.rb', line 256 def file? s = lstat! s and s.file? end |
#inspect ⇒ Object
228 229 230 |
# File 'lib/xcode-installer/install.rb', line 228 def inspect "\#<#{self.class} #{path()}>" end |
#lstat ⇒ Object
328 329 330 331 332 333 334 |
# File 'lib/xcode-installer/install.rb', line 328 def lstat if dereference? @lstat ||= File.stat(path()) else @lstat ||= File.lstat(path()) end end |
#lstat! ⇒ Object
336 337 338 339 340 |
# File 'lib/xcode-installer/install.rb', line 336 def lstat! lstat() rescue SystemCallError nil end |
#path ⇒ Object
232 233 234 235 236 237 238 |
# File 'lib/xcode-installer/install.rb', line 232 def path if @path File.path(@path) else join(@prefix, @rel) end end |
#pipe? ⇒ Boolean
286 287 288 289 |
# File 'lib/xcode-installer/install.rb', line 286 def pipe? s = lstat! s and s.pipe? end |
#platform_support ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/xcode-installer/install.rb', line 433 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
463 464 465 466 467 468 469 470 471 472 |
# File 'lib/xcode-installer/install.rb', line 463 def postorder_traverse if directory? entries().each do |ent| ent.postorder_traverse do |e| yield e end end end yield self end |
#prefix ⇒ Object
240 241 242 |
# File 'lib/xcode-installer/install.rb', line 240 def prefix @prefix || @path end |
#preorder_traverse ⇒ Object Also known as: traverse
453 454 455 456 457 458 459 |
# File 'lib/xcode-installer/install.rb', line 453 def preorder_traverse stack = [self] while ent = stack.pop yield ent stack.concat ent.entries.reverse if ent.directory? end end |
#rel ⇒ Object
244 245 246 |
# File 'lib/xcode-installer/install.rb', line 244 def rel @rel end |
#remove ⇒ Object
413 414 415 416 417 418 419 |
# File 'lib/xcode-installer/install.rb', line 413 def remove if directory? remove_dir1 else remove_file end end |
#remove_dir1 ⇒ Object
421 422 423 424 425 |
# File 'lib/xcode-installer/install.rb', line 421 def remove_dir1 platform_support { Dir.rmdir path().chomp(?/) } end |
#remove_file ⇒ Object
427 428 429 430 431 |
# File 'lib/xcode-installer/install.rb', line 427 def remove_file platform_support { File.unlink path } end |
#socket? ⇒ Boolean
281 282 283 284 |
# File 'lib/xcode-installer/install.rb', line 281 def socket? s = lstat! s and s.socket? end |
#stat ⇒ Object
306 307 308 309 310 311 312 313 314 |
# File 'lib/xcode-installer/install.rb', line 306 def stat return @stat if @stat if lstat() and lstat().symlink? @stat = File.stat(path()) else @stat = lstat() end @stat end |
#stat! ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/xcode-installer/install.rb', line 316 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
266 267 268 269 |
# File 'lib/xcode-installer/install.rb', line 266 def symlink? s = lstat! s and s.symlink? end |