Exemple #1
0
	LocatableFile* _GetFile(const BString& directoryPath, const BString& name)
	{
		// if already known return the file
		LocatableEntry* entry = _LookupEntry(EntryPath(directoryPath, name));
		if (entry != NULL) {
			LocatableFile* file = dynamic_cast<LocatableFile*>(entry);
			if (file == NULL)
				return NULL;

			if (file->AcquireReference() == 0) {
				fEntries.Remove(file);
				fDeadEntries.Insert(file);
			} else
				return file;
		}

		// no such file yet -- create it
		BString normalizedDirPath;
		_NormalizePath(directoryPath, normalizedDirPath);
		LocatableDirectory* directory = _GetDirectory(normalizedDirPath);
		if (directory == NULL)
			return NULL;

		LocatableFile* file = new(std::nothrow) LocatableFile(this, directory,
			name);
		if (file == NULL) {
			directory->ReleaseReference();
			return NULL;
		}

		directory->AddEntry(file);

		fEntries.Insert(file);
		return file;
	}
Exemple #2
0
	virtual void LocatableEntryUnused(LocatableEntry* entry)
	{
		AutoLocker<FileManager> lock(fManager);
		if (fEntries.Lookup(EntryPath(entry)) == entry)
			fEntries.Remove(entry);

		LocatableDirectory* parent = entry->Parent();
		if (parent != NULL)
			parent->RemoveEntry(entry);
	}
Exemple #3
0
	void EntryLocated(const BString& path, const BString& locatedPath)
	{
		BString directory;
		BString name;
		_SplitPath(path, directory, name);

		LocatableEntry* entry = _LookupEntry(EntryPath(directory, name));
		if (entry == NULL)
			return;

		_LocateEntry(entry, locatedPath, false, true);
	}
Exemple #4
0
	LocatableDirectory* _GetDirectory(const BString& path)
	{
		BString directoryPath;
		BString fileName;
		_SplitNormalizedPath(path, directoryPath, fileName);

		// if already know return the directory
		LocatableEntry* entry
			= _LookupEntry(EntryPath(directoryPath, fileName));
		if (entry != NULL) {
			LocatableDirectory* directory
				= dynamic_cast<LocatableDirectory*>(entry);
			if (directory == NULL)
				return NULL;
			directory->AcquireReference();
			return directory;
		}

		// get the parent directory
		LocatableDirectory* parentDirectory = NULL;
		if (directoryPath.Length() > 0) {
			parentDirectory = _GetDirectory(directoryPath);
			if (parentDirectory == NULL)
				return NULL;
		}

		// create a new directory
		LocatableDirectory* directory = new(std::nothrow) LocatableDirectory(
			this, parentDirectory, path);
		if (directory == NULL) {
			parentDirectory->ReleaseReference();
			return NULL;
		}

		// auto-locate, if possible
		if (fIsLocal) {
			BString dirPath;
			directory->GetPath(dirPath);
			directory->SetLocatedPath(dirPath, false);
		} else if (parentDirectory != NULL
			&& parentDirectory->State() != LOCATABLE_ENTRY_UNLOCATED) {
			BString locatedDirectoryPath;
			if (parentDirectory->GetLocatedPath(locatedDirectoryPath))
				_LocateEntryInParentDir(directory, locatedDirectoryPath, true);
		}

		if (parentDirectory != NULL)
			parentDirectory->AddEntry(directory);

		fEntries.Insert(directory);
		return directory;
	}
Exemple #5
0
	virtual void LocatableEntryUnused(LocatableEntry* entry)
	{
		AutoLocker<FileManager> lock(fManager);
		if (fEntries.Lookup(EntryPath(entry)) == entry)
			fEntries.Remove(entry);
		else {
			DeadEntryList::Iterator iterator = fDeadEntries.GetIterator();
			while (iterator.HasNext()) {
				if (iterator.Next() == entry) {
					fDeadEntries.Remove(entry);
					break;
				}
			}
		}
	}
Exemple #6
0
	bool Compare(const EntryPath& key, const LocatableEntry* value) const
	{
		return EntryPath(value) == key;
	}
Exemple #7
0
	size_t Hash(const LocatableEntry* value) const
	{
		return HashKey(EntryPath(value));
	}