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_.
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/xcode-installer/install.rb', line 192 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
253 254 255 256 |
# File 'lib/xcode-installer/install.rb', line 253 def blockdev? s = lstat! s and s.blockdev? end |
#chardev? ⇒ Boolean
248 249 250 251 |
# File 'lib/xcode-installer/install.rb', line 248 def chardev? s = lstat! s and s.chardev? end |
#chmod(mode) ⇒ Object
319 320 321 322 323 324 325 |
# File 'lib/xcode-installer/install.rb', line 319 def chmod(mode) if symlink? File.lchmod mode, path() if have_lchmod? else File.chmod mode, path() end end |
#chown(uid, gid) ⇒ Object
327 328 329 330 331 332 333 |
# File 'lib/xcode-installer/install.rb', line 327 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
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/xcode-installer/install.rb', line 335 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
369 370 371 372 373 374 375 |
# File 'lib/xcode-installer/install.rb', line 369 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
377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/xcode-installer/install.rb', line 377 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
225 226 227 |
# File 'lib/xcode-installer/install.rb', line 225 def dereference? @deref end |
#directory? ⇒ Boolean
238 239 240 241 |
# File 'lib/xcode-installer/install.rb', line 238 def directory? s = lstat! s and s.directory? end |
#door? ⇒ Boolean
270 271 272 273 |
# File 'lib/xcode-installer/install.rb', line 270 def door? s = lstat! s and (s.mode & 0xF000 == S_IF_DOOR) end |
#entries ⇒ Object
275 276 277 278 279 280 281 |
# File 'lib/xcode-installer/install.rb', line 275 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
229 230 231 |
# File 'lib/xcode-installer/install.rb', line 229 def exist? lstat! ? true : false end |
#file? ⇒ Boolean
233 234 235 236 |
# File 'lib/xcode-installer/install.rb', line 233 def file? s = lstat! s and s.file? end |
#inspect ⇒ Object
205 206 207 |
# File 'lib/xcode-installer/install.rb', line 205 def inspect "\#<#{self.class} #{path()}>" end |
#lstat ⇒ Object
305 306 307 308 309 310 311 |
# File 'lib/xcode-installer/install.rb', line 305 def lstat if dereference? @lstat ||= File.stat(path()) else @lstat ||= File.lstat(path()) end end |
#lstat! ⇒ Object
313 314 315 316 317 |
# File 'lib/xcode-installer/install.rb', line 313 def lstat! lstat() rescue SystemCallError nil end |
#path ⇒ Object
209 210 211 212 213 214 215 |
# File 'lib/xcode-installer/install.rb', line 209 def path if @path File.path(@path) else join(@prefix, @rel) end end |
#pipe? ⇒ Boolean
263 264 265 266 |
# File 'lib/xcode-installer/install.rb', line 263 def pipe? s = lstat! s and s.pipe? end |
#platform_support ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/xcode-installer/install.rb', line 410 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
440 441 442 443 444 445 446 447 448 449 |
# File 'lib/xcode-installer/install.rb', line 440 def postorder_traverse if directory? entries().each do |ent| ent.postorder_traverse do |e| yield e end end end yield self end |
#prefix ⇒ Object
217 218 219 |
# File 'lib/xcode-installer/install.rb', line 217 def prefix @prefix || @path end |
#preorder_traverse ⇒ Object Also known as: traverse
430 431 432 433 434 435 436 |
# File 'lib/xcode-installer/install.rb', line 430 def preorder_traverse stack = [self] while ent = stack.pop yield ent stack.concat ent.entries.reverse if ent.directory? end end |
#rel ⇒ Object
221 222 223 |
# File 'lib/xcode-installer/install.rb', line 221 def rel @rel end |
#remove ⇒ Object
390 391 392 393 394 395 396 |
# File 'lib/xcode-installer/install.rb', line 390 def remove if directory? remove_dir1 else remove_file end end |
#remove_dir1 ⇒ Object
398 399 400 401 402 |
# File 'lib/xcode-installer/install.rb', line 398 def remove_dir1 platform_support { Dir.rmdir path().chomp(?/) } end |
#remove_file ⇒ Object
404 405 406 407 408 |
# File 'lib/xcode-installer/install.rb', line 404 def remove_file platform_support { File.unlink path } end |
#socket? ⇒ Boolean
258 259 260 261 |
# File 'lib/xcode-installer/install.rb', line 258 def socket? s = lstat! s and s.socket? end |
#stat ⇒ Object
283 284 285 286 287 288 289 290 291 |
# File 'lib/xcode-installer/install.rb', line 283 def stat return @stat if @stat if lstat() and lstat().symlink? @stat = File.stat(path()) else @stat = lstat() end @stat end |
#stat! ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/xcode-installer/install.rb', line 293 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
243 244 245 246 |
# File 'lib/xcode-installer/install.rb', line 243 def symlink? s = lstat! s and s.symlink? end |