In: |
p4table.rb
|
Parent: | Object |
Class for representing files that are versioned in the depot. Files can be either (a) the meta file containing the metadata about the record (basically a "p4 job -o <recid>") or they can be other files which are attached to the record.
id | [R] | |
name | [R] |
Open this file for add
# File p4table.rb, line 336 336: def add 337: if ( exists? ) 338: raise( RuntimeError, "Can't open existing file for add", caller ) 339: end 340: P4Global.tagged.run_sync 341: P4Global.tagged.run_add( ws_path() ) 342: end
Open this file for delete
# File p4table.rb, line 359 359: def delete 360: if ( ! exists? ) 361: raise( RuntimeError, "Can't delete non-existent file", caller ) 362: end 363: 364: P4Global.tagged.run_sync 365: P4Global.tagged.run_delete( depot_path() ) 366: end
Compute the depot path based on the table storage map and the id
# File p4table.rb, line 313 313: def depot_path 314: return @depot_path if @depot_path 315: table_path = @id.table.storage_map( @id ).join( "/" ) 316: @depot_path = [ DEPOT_ROOT_PATH, table_path, @id.seq_str, @name ].join( "/" ) 317: end
Explicitly set the depot path for a file. Needed to allow old records to be found in their old locations even if the storage map has since changed.
# File p4table.rb, line 306 306: def depot_path=( path ) 307: @depot_path = path 308: end
Open this file for edit
# File p4table.rb, line 347 347: def edit 348: if ( ! exists? ) 349: raise( RuntimeError,"Can't open non-existent file for edit", caller) 350: end 351: 352: P4Global.tagged.run_sync 353: P4Global.tagged.run_edit( depot_path() ) 354: end
Set the existence flag for a file explicitly
# File p4table.rb, line 329 329: def exists=( bool ) 330: @exists = bool 331: end
Create the directory for the workspace file
# File p4table.rb, line 391 391: def mkdir 392: P4Global.tagged.run_sync 393: dirs = ws_path.split( SEP ) 394: dirs.pop 395: dir = "" 396: dirs.each do 397: |d| 398: dir += d + SEP 399: Dir.mkdir( dir ) unless File.directory?( dir ) 400: end 401: end
Read the contents of the file (returns a String)
# File p4table.rb, line 371 371: def read 372: P4Global.tagged.run_sync 373: f = File.open( ws_path, "r" ) 374: buf = f.read 375: f.close 376: return buf 377: end
Render the filename as a string (we use depot syntax)
# File p4table.rb, line 406 406: def to_s 407: depot_file 408: end
Write the contents of the file
# File p4table.rb, line 382 382: def write( string ) 383: P4Global.tagged.run_sync 384: mkdir 385: File.open( ws_path, "w" ) { |f| f.write( string ) } 386: end
Convert the depot path into a client path. Obviously this precludes complex client maps as we don’t want to reimplement Perforce mappings in Ruby.
# File p4table.rb, line 292 292: def ws_path 293: return @ws_path if ( @ws_path ) 294: 295: root = P4Global.tagged.fetch_client[ "Root" ] 296: path = depot_path.sub( DEPOT_ROOT_PATH, root ) 297: @ws_path = path.gsub!( "/", SEP ) 298: end