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_.
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/xcode-installer/install.rb', line 179 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
240 241 242 243 |
# File 'lib/xcode-installer/install.rb', line 240 def blockdev? s = lstat! s and s.blockdev? end |
#chardev? ⇒ Boolean
235 236 237 238 |
# File 'lib/xcode-installer/install.rb', line 235 def chardev? s = lstat! s and s.chardev? end |
#chmod(mode) ⇒ Object
306 307 308 309 310 311 312 |
# File 'lib/xcode-installer/install.rb', line 306 def chmod(mode) if symlink? File.lchmod mode, path() if have_lchmod? else File.chmod mode, path() end end |
#chown(uid, gid) ⇒ Object
314 315 316 317 318 319 320 |
# File 'lib/xcode-installer/install.rb', line 314 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
322 323 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 |
# File 'lib/xcode-installer/install.rb', line 322 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
356 357 358 359 360 361 362 |
# File 'lib/xcode-installer/install.rb', line 356 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
364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/xcode-installer/install.rb', line 364 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
212 213 214 |
# File 'lib/xcode-installer/install.rb', line 212 def dereference? @deref end |
#directory? ⇒ Boolean
225 226 227 228 |
# File 'lib/xcode-installer/install.rb', line 225 def directory? s = lstat! s and s.directory? end |
#door? ⇒ Boolean
257 258 259 260 |
# File 'lib/xcode-installer/install.rb', line 257 def door? s = lstat! s and (s.mode & 0xF000 == S_IF_DOOR) end |
#entries ⇒ Object
262 263 264 265 266 267 268 |
# File 'lib/xcode-installer/install.rb', line 262 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
216 217 218 |
# File 'lib/xcode-installer/install.rb', line 216 def exist? lstat! ? true : false end |
#file? ⇒ Boolean
220 221 222 223 |
# File 'lib/xcode-installer/install.rb', line 220 def file? s = lstat! s and s.file? end |
#inspect ⇒ Object
192 193 194 |
# File 'lib/xcode-installer/install.rb', line 192 def inspect "\#<#{self.class} #{path()}>" end |
#lstat ⇒ Object
292 293 294 295 296 297 298 |
# File 'lib/xcode-installer/install.rb', line 292 def lstat if dereference? @lstat ||= File.stat(path()) else @lstat ||= File.lstat(path()) end end |
#lstat! ⇒ Object
300 301 302 303 304 |
# File 'lib/xcode-installer/install.rb', line 300 def lstat! lstat() rescue SystemCallError nil end |
#path ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/xcode-installer/install.rb', line 196 def path if @path File.path(@path) else join(@prefix, @rel) end end |
#pipe? ⇒ Boolean
250 251 252 253 |
# File 'lib/xcode-installer/install.rb', line 250 def pipe? s = lstat! s and s.pipe? end |
#platform_support ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/xcode-installer/install.rb', line 397 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
427 428 429 430 431 432 433 434 435 436 |
# File 'lib/xcode-installer/install.rb', line 427 def postorder_traverse if directory? entries().each do |ent| ent.postorder_traverse do |e| yield e end end end yield self end |
#prefix ⇒ Object
204 205 206 |
# File 'lib/xcode-installer/install.rb', line 204 def prefix @prefix || @path end |
#preorder_traverse ⇒ Object Also known as: traverse
417 418 419 420 421 422 423 |
# File 'lib/xcode-installer/install.rb', line 417 def preorder_traverse stack = [self] while ent = stack.pop yield ent stack.concat ent.entries.reverse if ent.directory? end end |
#rel ⇒ Object
208 209 210 |
# File 'lib/xcode-installer/install.rb', line 208 def rel @rel end |
#remove ⇒ Object
377 378 379 380 381 382 383 |
# File 'lib/xcode-installer/install.rb', line 377 def remove if directory? remove_dir1 else remove_file end end |
#remove_dir1 ⇒ Object
385 386 387 388 389 |
# File 'lib/xcode-installer/install.rb', line 385 def remove_dir1 platform_support { Dir.rmdir path().chomp(?/) } end |
#remove_file ⇒ Object
391 392 393 394 395 |
# File 'lib/xcode-installer/install.rb', line 391 def remove_file platform_support { File.unlink path } end |
#socket? ⇒ Boolean
245 246 247 248 |
# File 'lib/xcode-installer/install.rb', line 245 def socket? s = lstat! s and s.socket? end |
#stat ⇒ Object
270 271 272 273 274 275 276 277 278 |
# File 'lib/xcode-installer/install.rb', line 270 def stat return @stat if @stat if lstat() and lstat().symlink? @stat = File.stat(path()) else @stat = lstat() end @stat end |
#stat! ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/xcode-installer/install.rb', line 280 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
230 231 232 233 |
# File 'lib/xcode-installer/install.rb', line 230 def symlink? s = lstat! s and s.symlink? end |