filesys.h #1

  • //
  • guest/
  • alan_petersen/
  • piper/
  • mac/
  • R2.0/
  • Perforce/
  • p4api/
  • Headers/
  • filesys.h
  • View
  • Commits
  • Open Download .zip Download (12 KB)
/*
 * Copyright 1995, 1996 Perforce Software.  All rights reserved.
 *
 * This file is part of Perforce - the FAST SCM System.
 */

/*
 * FileSys.h - OS specific file manipulation
 *
 * Public classes:
 *
 *	FileSys - a file handle, with all the trimmings
 *
 * Static Public methods:
 *
 *	FileSys::Create() - create a FileSys, given its file type
 *	FileSys::CreateTemp() - create, destructor deletes the file
 *	FileSys::CreateGloablTemp() - Temp, constructor makes a global name
 *	FileSys::FileExists() - does the passed filepath exist in the file system
 *	FileSys::Perm() - translate string perm to enum
 *
 * Public methods:
 *
 *	FileSys::Set() - set file name
 *	FileSys::Name() - get file name
 *	FileSys::GetType() - get type previously set
 *	FileSys::IsTextual() - return if type is one of text types
 *	FileSys::IsExec() - return if type indicates executable bit set
 *	FileSys::DoIndirectWrites() - updates should write temp/rename
 *
 *	FileSys::MakeGlobalTemp() - make a temp name in a global directory
 *	FileSys::MakeLocalTemp() - make a temp name in same dir as file
 *
 *	FileSys::IsDeleteOnClose() - will file be removed on close?
 *	FileSys::SetDeleteOnClose() - file will be removed
 *	FileSys::ClearDeleteOnClose() - file won't be removed
 *
 *	FileSys::Perms() - set file permission for close after write
 *	FileSys::ModTime() - set mod time for close after write
 *	FileSys::ChmodTime() - use modTime value to change mod time directly
 *
 *	FileSys::Open() - open named file according to mode
 *	FileSys::Write() - write a block into file
 *	FileSys::Read() - read a block from file
 *	FileSys::ReadLine() - read a line into string
 *	FileSys::ReadWhole() - read whole file into string
 *	FileSys::Close() - close file description
 *
 *	FileSys::Stat() - return flags if file exists, writable
 *	FileSys::Truncate() - set file to zero length if it exists
 *	FileSys::Unlink() - remove single file
 *
 *	FileSys::GetFd() - return underlying int fd, FST_BINARY only
 *	FileSys::GetSize() - return file size, FST_BINARY,TEXT,ATEXT only
 *	FileSys::GetOwner() - return the UID of the file owner
 *	FileSys::GetDiskSpace() - fill in data about filesystem space usage.
 *	FileSys::Seek() - seek to offset, FST_BINARY,TEXT,ATEXT only
 *	FileSys::Tell() - file position, FST_BINARY,TEXT,ATEXT only
 *
 *	FileSys::ScanDir() - return a list of directory contents
 *	FileSys::MkDir() - make a directory for the current file
 *	FileSys::RmDir() - remove the directory of the current file
 *	FileSys::Rename() - rename file to target
 *	FileSys::ReadFile() - open, read whole file into string, close
 *	FileSys::WriteFile() - open, write whole file from string, close
 *	FileSys::Chmod() - change permissions
 *	FileSys::Compare() - compare file against target
 *	FileSys::Copy - copy one file to another
 *	FileSys::Digest() - return a fingerprint of the file contents
 *	FileSys::Chmod2() - copy a file to get ownership and set perms
 *	FileSys::Fsync() - sync file state to disk
 *
 *	FileSys::CheckType() - look at the file and see if it is binary, etc
 */

# ifdef OS_NT
# define DOUNICODE ( CharSetApi::isUnicode((CharSetApi::CharSet)GetCharSetPriv()) )
# endif

enum FileSysType
{
	// Base types

	FST_TEXT =	0x0001,	// file is text
	FST_BINARY =	0x0002,	// file is binary
	FST_DIRECTORY =	0x0005,	// it's a directory
	FST_SYMLINK =	0x0006,	// it's a symlink
	FST_RESOURCE =	0x0007,	// Macintosh resource file
	FST_SPECIAL =	0x0008,	// not a regular file
	FST_MISSING =	0x0009,	// no file at all
	FST_CANTTELL =	0x000A,	// can read file to find out
	FST_EMPTY =	0x000B,	// file is empty
	FST_UNICODE =	0x000C,	// file is unicode
	FST_UTF16 =	0x000E,	// stream is utf8 convert to utf16

	FST_MASK =	0x000F,	// mask for types

	// Compression Modifiers

	FST_C_ASIS =	0x0400,	// replacing FST_M_COMP
	FST_C_GZIP =	0x0800,	// for gziped files
	FST_C_GUNZIP =	0x0c00,	// for compress on client
	FST_C_MASK =	0x0c00,

	// Modifiers

	FST_M_APPEND =	0x0010,	// open always append
	FST_M_EXCL =	0x0020,	// open exclusive create
	FST_M_SYNC =	0x0040,	// fsync on close

	FST_M_EXEC = 	0x0100,	// file is executable
	FST_M_APPLE =	0x0200,	// apple single/double encoding
	FST_M_COMP =	0x0400, // file is somehow compressed

	FST_M_MASK =	0x0ff0,	// mask for modifiers

	// Line ending types, loosely mapped to LineType

	FST_L_LOCAL =	0x0000,	// LineTypeLocal
	FST_L_LF =	0x1000,	// LineTypeRaw
	FST_L_CR =	0x2000,	// LineTypeCr
	FST_L_CRLF =	0x3000,	// LineTypeCrLf
	FST_L_LFCRLF =	0x4000,	// LineTypeLfcrlf

	FST_L_MASK =	0xf000,	// mask for LineTypes

	// Composite types, for filesys.cc

	FST_ATEXT =	0x0011,	// append-only text
	FST_XTEXT =	0x0101,	// executable text
	FST_RTEXT =	0x1001,	// raw text
	FST_RXTEXT =	0x1101,	// executable raw text
	FST_CBINARY =	0x0402,	// pre-compressed binary
	FST_XBINARY =	0x0102,	// executable binary
	FST_APPLETEXT =	0x0201,	// apple format text
	FST_APPLEFILE =	0x0202,	// apple format binary
	FST_XAPPLEFILE =0x0302,	// executable apple format binary
	FST_XUNICODE =	0x010C,	// executable unicode text
	FST_XUTF16 =	0x010E,	// stream is utf8 convert to utf16
	FST_RCS =	0x1041,	// RCS temporary file: raw text, sync on close
	FST_GZIP =	0x0802,	// file is gzip
	FST_GUNZIP =	0x0c02,	// stream is gzip
	FST_GZIPTEXT =  0x0801, // file is text gzipped
};

enum FileStatFlags {
	FSF_EXISTS 	= 0x01,	// file exists
	FSF_WRITEABLE	= 0x02,	// file is user-writable
	FSF_DIRECTORY	= 0x04,	// file is a directory
	FSF_SYMLINK	= 0x08,	// file is symlink
	FSF_SPECIAL	= 0x10,	// file is not regular
	FSF_EXECUTABLE	= 0x20,	// file is executable
	FSF_EMPTY	= 0x40,	// file is empty
	FSF_HIDDEN	= 0x80	// file is invisible (hidden)
} ;

enum FileSysAttr {
	FSA_HIDDEN	= 0x01	// file is invisible (hidden)
} ;

enum FileOpenMode {
	FOM_READ,		// open for reading
	FOM_WRITE,		// open for writing
	FOM_RW			// open for write, but don't trunc, allow read
} ;

enum FilePerm {
	FPM_RO,		// leave file read-only
	FPM_RW,		// leave file read-write
	FPM_ROO,	// leave file read-only (owner)
	// following two enums are for key file and dir permissions
	FPM_RXO,	// set file read-execute (owner) NO W
	FPM_RWO,	// set file read-write (owner) NO X
	FPM_RWXO	// set file read-write-execute (owner)
} ;

class StrArray;
class CharSetCvt;
class MD5;
class StrBuf;

class DiskSpaceInfo {

    public:

	    		DiskSpaceInfo();
			~DiskSpaceInfo();

	P4INT64		blockSize;
	P4INT64		totalBytes;
	P4INT64		usedBytes;
	P4INT64		freeBytes;
	int		pctUsed;
	StrBuf		*fsType;
} ;

class FileSys {

    public:
	// Creators

	static FileSys *Create( FileSysType type );

	static FileSys *CreateTemp( FileSysType type ) {
				FileSys *f = Create( type );
				f->SetDeleteOnClose();
				return f;
			}

	static FileSys *CreateGlobalTemp( FileSysType type ) {
				FileSys *f = Create( type );
				f->SetDeleteOnClose();
				f->MakeGlobalTemp();
				return f;
			}

	static FilePerm Perm( const char *p );

	static bool     FileExists( const char *p );

	static int	BufferSize();

	static bool	IsRelative( const StrPtr &p );

# ifdef OS_NT
	static bool	IsUNC( const StrPtr &p );
# endif

	virtual void	SetBufferSize( size_t ) { }

	int		IsUnderPath( const StrPtr &path );

	static int	SymlinksSupported()
# ifdef OS_NT
		;		// Have to probe the system to decide
# else
# ifdef HAVE_SYMLINKS
				{ return 1; }
# else
				{ return 0; }
# endif
# endif

	// Get/set perms, modtime

	void		Perms( FilePerm p ) { perms = p; }
	void		ModTime( StrPtr *u ) { modTime = u->Atoi(); }
	void		ModTime( time_t t ) { modTime = (int)t; }
	time_t		GetModTime() { return modTime; }

	// Set filesize hint for NT fragmentation avoidance

	void		SetSizeHint( offL_t l ) { sizeHint = l; }
	offL_t		GetSizeHint() { return sizeHint; }

	// Set advise hint (don't pollute O.S cache with archive content)
 
	virtual void    SetCacheHint() { cacheHint = 1; } 

	// Initialize digest

	virtual void	SetDigest( MD5 *m );

	// Get type info

	FileSysType 	GetType() { return type; }
	int		IsExec() { return ( type & FST_M_EXEC ); }
	int		IsTextual() { 
				return ( type & FST_MASK ) == FST_TEXT || 
				       ( type & FST_MASK ) == FST_UNICODE ||
				       ( type & FST_MASK ) == FST_UTF16;
			}
	int		IsUnicode() { 
				return ( type & FST_MASK ) == FST_UNICODE ||
				       ( type & FST_MASK ) == FST_UTF16;
			}
	int             IsSymlink() {
	                        return ( type & FST_MASK ) == FST_SYMLINK;
	}


	// Read/write file access, provided by derived class

			FileSys();
	virtual		~FileSys();

# ifdef OS_NT
	virtual void	SetLFN( const StrPtr &name );
# endif
	virtual void	Set( const StrPtr &name );
	virtual void	Set( const StrPtr &name, Error *e );
	virtual StrPtr	*Path() { return &path; }
	virtual int	DoIndirectWrites();
	virtual void	Translator( CharSetCvt * );

	virtual void	Open( FileOpenMode mode, Error *e ) = 0;
	virtual void	Write( const char *buf, int len, Error *e ) = 0;
	virtual int	Read( char *buf, int len, Error *e ) = 0;
	virtual void	Close( Error *e ) = 0;


	virtual int	Stat() = 0;
	virtual int	StatModTime() = 0;
	virtual void	Truncate( Error *e ) = 0;
	virtual void	Truncate( offL_t offset, Error *e ) = 0;
	virtual void	Unlink( Error *e = 0 ) = 0;
	virtual void	Rename( FileSys *target, Error *e ) = 0;
	virtual void	Chmod( FilePerm perms, Error *e ) = 0;
	virtual void	ChmodTime( Error *e ) = 0;
	virtual void	SetAttribute( FileSysAttr attrs, Error *e ) { };

	virtual void	Fsync( Error *e ) { }

	// NB: these for ReadFile only; interface will likely change
	virtual bool	HasOnlyPerm( FilePerm perms );
	virtual int	GetFd();
	virtual int     GetOwner();
	virtual offL_t	GetSize();
	virtual void	Seek( offL_t offset, Error * );
	virtual offL_t	Tell();

	// Convenience wrappers for above

	void		Chmod( Error *e ) { Chmod( perms, e ); }
	void		Chmod( const char *perms, Error *e )
			{ Chmod( Perm( perms ), e ); } 

	char *		Name() { return Path()->Text(); }
	void		Set( const char *name ) { Set( StrRef( name ) ); }
	void		Set( const char *name, Error *e )
	                { Set( StrRef( name ), e ); }

	void		Write( const StrPtr &b, Error *e ) 
			{ Write( b.Text(), b.Length(), e ); }

	void		Write( const StrPtr *b, Error *e ) 
			{ Write( b->Text(), b->Length(), e ); }

	// Tempfile support

	void		MakeGlobalTemp();
	virtual void	MakeLocalTemp( char *file );
	int		IsDeleteOnClose() { return isTemp; }
	void		SetDeleteOnClose() { isTemp = 1; }
	void		ClearDeleteOnClose() { isTemp = 0; }

	// Meta operations

	virtual StrArray *ScanDir( Error *e );

	virtual void	MkDir( const StrPtr &p, Error *e );
	void		MkDir( Error *e ) { MkDir( path, e ); }

	virtual void	PurgeDir( const char *p, Error *e );
	virtual void	RmDir( const StrPtr &p, Error *e );
	void		RmDir( Error *e = 0 ) { RmDir( path, e ); }

	FileSysType	CheckType( int scan = -1 );

# if defined ( OS_MACOSX )
	FileSysType	CheckTypeMac();
# endif

	// Type generic operations

	virtual int	ReadLine( StrBuf *buf, Error *e );
	void		ReadWhole( StrBuf *buf, Error *e );

	// Type generic, whole file operations

	void		ReadFile( StrBuf *buf, Error *e );
	void		WriteFile( const StrPtr *buf, Error *e );
	int		Compare( FileSys *other, Error *e );
	void 		Copy( FileSys *targetFile, FilePerm perms, Error *e );
	virtual void	Digest( StrBuf *digest, Error *e );
	void		Chmod2( FilePerm perms, Error *e );
	void		Chmod2( const char *p, Error *e )
			{ Chmod2( Perm( p ), e ); }

	void		Cleanup();

	// Character Set operations

	void		SetCharSetPriv( int x = 0 ) { charSet = x; }
	int		GetCharSetPriv() { return charSet; }
	void		SetContentCharSetPriv( int x = 0 ) { content_charSet = x; }
	int		GetContentCharSetPriv() { return content_charSet; }

	void		GetDiskSpace( DiskSpaceInfo *info, Error *e );

	void		LowerCasePath();
    protected:

	FileOpenMode	mode;		// read or write
	FilePerm	perms;		// leave read-only or read-write
	int		modTime;	// stamp file mod date on close
	offL_t		sizeHint;       // how big will the file get ?
	StrBuf		path;
	FileSysType 	type;
	MD5		*checksum;      // if verifying file transfer
	int		cacheHint;      // don't pollute cache

# ifdef OS_NT
	int		LFN;
# endif

    private:
	void		TempName( char *buf );

	int		isTemp;

	int		charSet;
	int		content_charSet;

} ;
# Change User Description Committed
#1 15071 alan_petersen Populate -o //guest/perforce_software/piper/...
//guest/alan_petersen/piper/....
//guest/perforce_software/piper/mac/R2.0/Perforce/p4api/Headers/filesys.h
#2 13626 alan_petersen Copying using piper_mac_main2r2.0
#1 12962 alan_petersen Populate -o //guest/perforce_software/piper/mac/main/...
//guest/perforce_software/piper/mac/R2.0/....
//guest/perforce_software/piper/mac/main/Perforce/p4api/Headers/filesys.h
#2 12961 alan_petersen Piper 2.0 Mega Update

New Features/Functionality
- Added help menu redirecting to URL.
- Added readonly property for creating new workspaces.
- Added html hyperlinks for Copy link functionality.
- Added functionality for managing Finder Favorite items in sidebar.
- Redesigned the way mapping is stored in Piper.
- First version of syncing finder sidebar items with workspace mapping.
- Small sorting improvements.
- Creating Projects directory inside users home folder.
- Adding Projects folder to finder sidebar item.
- Creating and removing symbolic links accordingly to mapped folders.
- Preventing duplicate names in symbolic links.
- Refreshing symbolic links on mapping change inside application.
- Storing workspace and server details in p4 configuration for other applications to use.
- Added contextual menu items for Finder integration.
- Added services menu for Adobe Illustrator integration.
- Keyboard shortcuts for Illustrator integration.
- Code refactoring and fixes for mapping issues.
- Added Finder functionality to edit all files in folder.
- Added user friendly message when editing a file using Finder outside the workspace.
- Implemented hidden automatic login when opening application using Finder integration.
- Logging to file in ~/Library/Logs
- Unified workspace and all files views to show both local and depot files and folders.
- Removed my workspace view references and logic.
- Editing unmapped files on server.
- First version of adding file to unmapped folders.
- Showing opened by and edit actions in column details for all depot files.
- Improved mappings functionality.
- Enabled same feature options for mapped and unmapped folders and files.
- Redesigned from scratch mapping and unmapping procedures for adding and removing files.
- Implemented cleaning workspace using new mapping functionality. Removed debug overlay coloring.
- Automated workspace creation
- Improvements in editing files already mapped to workspace.
- Implemented deleting remote files.
- Implemented first version of move operation for remote files.
- Removing last workspace information when disconnecting from workspace using app menu.
- Implemented editing and submitting using symbolic links in project folder. New finder menu service for symbolic links Show in Piper which acts like share link functionality.
- New icons for files and folders not tracked in the filesystem.
- Improvements in showing file using share link.
- Switched to new way of retrieving files in order to show user changes.
- Redesigned and implemented new functionality for chaining operations with mapping.
- Improvements and redesign of Edit/add actions to use new chaining logic . Fixed issue with file edit.
- Improvements in window showing when using services.
- Simplified file loading so the local files appears only when remote are also loaded.
- Improved deleting of untracked files to avoid mapping and marking for delete.
- Enabling simple copy paste and moving of remote and local files.
- Added abort for exception handling in order to force crashing application on critical failures
- Added custom exception handling for catching runtime errors to log and crash instead of continuing in unstable state.
- Changed file copying to use mark for add .
- Simplified and fixed responding file representations to mapping changes.

Bug Fixes
- Fixed crash when synchronizing.
- Fixed sync issue when downloading directory without file size information.
- Fixed issue with unread list crashing when file is not existing on disk.
- Fixed incorrect sync progress calculation.
- Removed relative path issues.
- Fixed many of case-sensitivity problems.
- Fixed deprecated methods and related issues in OS X 10.10.
- Fixed folder rename not updating in column view. Revised and fixed many potential problems from implicit casting.
- Fixed missing sync button on fast sync completion.
- Refreshing mapping on synchronization. Fixed symbolic links not appearing until app is restarted.
- Fixed latest crashing of autosync.
- Fixed loading indicator issues.
- Fixed and redesigned submit dialog to work correctly with Submit All Files option in Finder.
- Fixed multiple error messages on network outage. Redesigned showing errors in main window.
- Fixed opening random locations when using Finder integration.
- Fixed issue when panel was detached from parent window.
- Fixed bug when creating new workspace wouldn't store default settings.
- Fixed memory issues with network operations.
- Fixes in relogging mappings and file listing.
- Improvements in editing unmapped files.
- Fixed crash when adding file outside workspace.
- Fixed breadcrumbs control issue.
- Fixed issue with double parent folders when opening unmapped files.
- Fixed crashes on sync after mapping new files.
- Fixed issue with editing file using Finder
-- Merging code and additional fixes in add button functionality.
- Fixed unsync not working
- Fixed submit panel issue not selecting files with different name case.
- Fixed missing revert and sync to workspace actions in some cases.
- Fixed issue with Submit and Edit finder actions. Improvements in stability of finder integration.
- Fixed issue with unsubmitted folders breaking status of files inside.
- Fixed issue with added files not showing correct icon and status.
- Fixed bug with file edit resulting in a new directory named exactly like a file.
- Fixed issue with reloading of subpath resulting in untracked folders.
- Fixed mapping issue when result was always view mapping not relative.
- Fixed submit panel showing more than once.
- Fixed illustrator services not working.
- Fixed userdefaults preferences problem with workspace name being null.
- Fixed userdefaults keypath problem of dot-containing workspace names.
- Forcing recreating of browser to possibly prevent pre-10.10 errors with automatic workspace selection.
- Fixed adding file to depot not presenting correct icon.
- Fixed issues with reverting a file that was marked for add.
- Presenting error when trying to submit untracked files.
- Fixed issue when submit files service crashed when using unmapped files.
- Fixed file representation disappearing when removing file.
- Fixed issue with symlinks resolving working on 10.10 only. Issue related to workspace selection not showing.
- Fixed error panel method calls unavailable in Mac OS versions before 10.10. Issue related to hanging error panels.
- Fixed removing a local file resulting in action progress freezing.
- Fixed open file not working after edit.
- Fixing crash when mapping changed. Issue related to moving local file to unmapped folder and other similar cases.
#1 11252 alan_petersen Rename/move file(s)
//guest/perforce_software/piper/mac/Perforce/p4api/Headers/filesys.h
#1 10744 alan_petersen Rename/move file(s)
//guest/perforce_software/piper/Perforce/p4api/Headers/filesys.h
#1 8919 Matt Attaway Initial add of Piper, a lightweight Perforce client for artists and designers.