Class: RSCM::P4Daemon

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/rscm/scm/perforce.rb

Instance Method Summary collapse

Constructor Details

#initialize(depotpath) ⇒ P4Daemon

Returns a new instance of P4Daemon.



439
440
441
# File 'lib/rscm/scm/perforce.rb', line 439

def initialize(depotpath)
  @depotpath = depotpath
end

Instance Method Details

#assert_runningObject



448
449
450
# File 'lib/rscm/scm/perforce.rb', line 448

def assert_running
  raise "p4d did not start properly" if timeout(10) { running? }
end

#launchObject



452
453
454
455
456
457
458
459
460
# File 'lib/rscm/scm/perforce.rb', line 452

def launch
  fork do
    mkdir_p(@depotpath)
    cd(@depotpath)
    debug "starting p4 server"
    exec("p4d")
  end
  at_exit { shutdown }
end

#running?Boolean

Returns:

  • (Boolean)


466
467
468
# File 'lib/rscm/scm/perforce.rb', line 466

def running?
  `p4 -p 1666 info 2>&1`!~ /Connect to server failed/
end

#shutdownObject



462
463
464
# File 'lib/rscm/scm/perforce.rb', line 462

def shutdown
  `p4 -p 1666 admin stop` if running?
end

#startObject



443
444
445
446
# File 'lib/rscm/scm/perforce.rb', line 443

def start
  launch
  assert_running
end