Class P4RecFile
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.

Methods
add    delete    depot_path    depot_path=    edit    exists=    exists?    mkdir    new    read    to_s    write    ws_path   
Attributes
:id  [R] 
:name  [R] 
Public Class methods
new( name, id )

Construct a new P4RecFile object based on the supplied filename and RecId.

# File P4table.rb, line 277
    def initialize( name, id )
	@name 		= name
	@id 		= id
	@exists 	= false
	@depot_path 	= nil
	@ws_path 	= nil
    end
Public Instance methods
ws_path()

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
    def ws_path
	return @ws_path if ( @ws_path )

	root = P4Global.tagged.fetch_client[ "Root" ]
	path = depot_path.sub( DEPOT_ROOT_PATH, root )
	@ws_path = path.gsub!( "/", SEP )
    end
depot_path=( path )

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
    def depot_path=( path )
	@depot_path = path
    end
depot_path()

Compute the depot path based on the table storage map and the id

# File P4table.rb, line 313
    def depot_path
	return @depot_path if @depot_path
	table_path = @id.table.storage_map( @id ).join( "/" )
	@depot_path = [ DEPOT_ROOT_PATH, table_path, @id.seq_str, @name ].join( "/" )
    end
exists?()

Does the file exist?

# File P4table.rb, line 322
    def exists?
	@exists
    end
exists=( bool )

Set the existence flag for a file explicitly

# File P4table.rb, line 329
    def exists=( bool )
	@exists = bool
    end
add()

Open this file for add

# File P4table.rb, line 336
    def add
	if ( exists? )
	    raise( RuntimeError, "Can't open existing file for add", caller )
	end
	P4Global.tagged.run_sync
	P4Global.tagged.run_add( ws_path() )
    end
edit()

Open this file for edit

# File P4table.rb, line 347
    def edit
	if ( ! exists? )
	    raise( RuntimeError,"Can't open non-existent file for edit", caller)
	end

	P4Global.tagged.run_sync
	P4Global.tagged.run_edit( depot_path() )
    end
delete()

Open this file for delete

# File P4table.rb, line 359
    def delete
	if ( ! exists? )
	    raise( RuntimeError, "Can't delete non-existent file", caller )
	end

	P4Global.tagged.run_sync
	P4Global.tagged.run_delete( depot_path() )
    end
read()

Read the contents of the file (returns a String)

# File P4table.rb, line 371
    def read
	P4Global.tagged.run_sync
	f = File.open( ws_path, "r" )
	buf = f.read
	f.close
	return buf
    end
write( string )

Write the contents of the file

# File P4table.rb, line 382
    def write( string )
	P4Global.tagged.run_sync
	mkdir
	File.open( ws_path, "w" ) { |f| f.write( string ) }
    end
mkdir()

Create the directory for the workspace file

# File P4table.rb, line 391
    def mkdir
	P4Global.tagged.run_sync
	dirs = ws_path.split( SEP )
	dirs.pop
	dir = ""
	dirs.each do
	    |d|
	    dir += d + SEP
	    Dir.mkdir( dir ) unless File.directory?( dir )
	end
    end
to_s()

Render the filename as a string (we use depot syntax)

# File P4table.rb, line 406
    def to_s
	depot_file
    end