diff options
Diffstat (limited to 'backends/fs')
| -rw-r--r-- | backends/fs/fs.h | 4 | ||||
| -rw-r--r-- | backends/fs/posix/posix-fs.cpp | 39 | ||||
| -rw-r--r-- | backends/fs/windows/windows-fs.cpp | 2 | 
3 files changed, 36 insertions, 9 deletions
diff --git a/backends/fs/fs.h b/backends/fs/fs.h index fe472cc005..36c7429828 100644 --- a/backends/fs/fs.h +++ b/backends/fs/fs.h @@ -86,13 +86,15 @@ public:  	 */  	static FilesystemNode *getRoot(); +#ifdef MACOSX  	/*  	 * Construct a node based on a path; the path is in the same format as it  	 * would be for calls to fopen().  	 *  	 * I.e. getNodeForPath(oldNode.path()) should create a new node identical to oldNode.  	 */ -//	static FilesystemNode *getNodeForPath(const String &path); +	static FilesystemNode *getNodeForPath(const String &path); +#endif  	virtual ~FilesystemNode() {} diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index bb50142769..86c29910b5 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -83,6 +83,12 @@ FilesystemNode *FilesystemNode::getRoot() {  	return new POSIXFilesystemNode();  } +#ifdef MACOSX +FilesystemNode *FilesystemNode::getNodeForPath(const String &path) { +	return new POSIXFilesystemNode(path); +} +#endif +  POSIXFilesystemNode::POSIXFilesystemNode() {  #ifndef __DC__  	char buf[MAXPATHLEN]; @@ -99,16 +105,33 @@ POSIXFilesystemNode::POSIXFilesystemNode() {  	_isDirectory = true;  } -/*  POSIXFilesystemNode::POSIXFilesystemNode(const String &p) { -	// TODO - extract last component from path -	_displayName = p; -	// TODO - check whether it is a directory, and whether the file actually exists +	int len = 0, offset = p.size(); +	struct stat st; +	 +	assert(offset > 0); + +	_path = p; + +	// Extract last component from path +	const char *str = p.c_str(); +	while (offset > 0 && str[offset-1] == '/') +		offset--; +	while (offset > 0 && str[offset-1] != '/') { +		len++; +		offset--; +	} +	_displayName = String(str + offset, len); + +	// Check whether it is a directory, and whether the file actually exists +#ifdef __DC__  	_isValid = true;  	_isDirectory = true; -	_path = p; +#else +	_isValid = (0 == stat(_path.c_str(), &st)); +	_isDirectory = S_ISDIR(st.st_mode); +#endif  } -*/  POSIXFilesystemNode::POSIXFilesystemNode(const POSIXFilesystemNode *node) {  	_displayName = node->_displayName; @@ -126,7 +149,7 @@ FSList *POSIXFilesystemNode::listDir(ListMode mode) const {  	FSList *myList = new FSList();  	if (dirp == NULL) return myList; -	 +  	// ... loop over dir entries using readdir  	while ((dp = readdir(dirp)) != NULL) {  		// Skip 'invisible' files @@ -136,6 +159,8 @@ FSList *POSIXFilesystemNode::listDir(ListMode mode) const {  		POSIXFilesystemNode entry;  		entry._displayName = dp->d_name;  		entry._path = _path; +		if (entry._path.lastChar() != '/') +			entry._path += '/';  		entry._path += dp->d_name;  #ifdef __DC__ diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp index 67273315be..0f6768c099 100644 --- a/backends/fs/windows/windows-fs.cpp +++ b/backends/fs/windows/windows-fs.cpp @@ -82,7 +82,7 @@ TCHAR* WindowsFilesystemNode::toUnicode(char *x) {  #endif  } -void WindowsFilesystemNode::addFile (FSList* list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) { +void WindowsFilesystemNode::addFile(FSList* list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) {  	WindowsFilesystemNode entry;  	char *asciiName = toAscii(find_data->cFileName);  	bool isDirectory;  | 
