예제 #1
0
status_t
FilePlaylistItem::_MoveIntoTrash(vector<entry_ref>* refs,
	vector<BString>* namesInTrash)
{
	char trashPath[B_PATH_NAME_LENGTH];
	status_t err = find_directory(B_TRASH_DIRECTORY, (*refs)[0].device,
		true /*create it*/, trashPath, B_PATH_NAME_LENGTH);
	if (err != B_OK) {
		fprintf(stderr, "failed to find Trash: %s\n", strerror(err));
		return err;
	}

	BDirectory trashDir(trashPath);
	err = trashDir.InitCheck();
	if (err != B_OK) {
		fprintf(stderr, "failed to init BDirectory for %s: %s\n",
			trashPath, strerror(err));
		return err;
	}

	for (vector<entry_ref>::size_type i = 0; i < refs->size(); i++) {
		BEntry entry(&(*refs)[i]);
		err = entry.InitCheck();
		if (err != B_OK) {
			fprintf(stderr, "failed to init BEntry for %s: %s\n",
				(*refs)[i].name, strerror(err));
			return err;
		}
	
		// Find a unique name for the entry in the trash
		(*namesInTrash)[i] = (*refs)[i].name;
		int32 uniqueNameIndex = 1;
		while (true) {
			BEntry test(&trashDir, (*namesInTrash)[i].String());
			if (!test.Exists())
				break;
			(*namesInTrash)[i] = (*refs)[i].name;
			(*namesInTrash)[i] << ' ' << uniqueNameIndex;
			uniqueNameIndex++;
		}
	
		// Remember the original path
		BPath originalPath;
		entry.GetPath(&originalPath);
	
		// Finally, move the entry into the trash
		err = entry.MoveTo(&trashDir, (*namesInTrash)[i].String());
		if (err != B_OK) {
			fprintf(stderr, "failed to move entry into trash %s: %s\n",
				trashPath, strerror(err));
			return err;
		}
	
		// Allow Tracker to restore this entry
		BNode node(&entry);
		BString originalPathString(originalPath.Path());
		node.WriteAttrString("_trk/original_path", &originalPathString);
	}

	return B_OK;
}
예제 #2
0
status_t
FilePlaylistItem::MoveIntoTrash()
{
	if (fNameInTrash.Length() != 0) {
		// Already in the trash!
		return B_ERROR;
	}

	char trashPath[B_PATH_NAME_LENGTH];
	status_t err = find_directory(B_TRASH_DIRECTORY, fRef.device,
		true /*create it*/, trashPath, B_PATH_NAME_LENGTH);
	if (err != B_OK) {
		fprintf(stderr, "failed to find Trash: %s\n", strerror(err));
		return err;
	}

	BEntry entry(&fRef);
	err = entry.InitCheck();
	if (err != B_OK) {
		fprintf(stderr, "failed to init BEntry for %s: %s\n",
			fRef.name, strerror(err));
		return err;
	}
	BDirectory trashDir(trashPath);
	if (err != B_OK) {
		fprintf(stderr, "failed to init BDirectory for %s: %s\n",
			trashPath, strerror(err));
		return err;
	}

	// Find a unique name for the entry in the trash
	fNameInTrash = fRef.name;
	int32 uniqueNameIndex = 1;
	while (true) {
		BEntry test(&trashDir, fNameInTrash.String());
		if (!test.Exists())
			break;
		fNameInTrash = fRef.name;
		fNameInTrash << ' ' << uniqueNameIndex;
		uniqueNameIndex++;
	}

	// Remember the original path
	BPath originalPath;
	entry.GetPath(&originalPath);

	// Finally, move the entry into the trash
	err = entry.MoveTo(&trashDir, fNameInTrash.String());
	if (err != B_OK) {
		fprintf(stderr, "failed to move entry into trash %s: %s\n",
			trashPath, strerror(err));
		return err;
	}

	// Allow Tracker to restore this entry
	BNode node(&entry);
	BString originalPathString(originalPath.Path());
	node.WriteAttrString("_trk/original_path", &originalPathString);

	return err;
}