本文整理汇总了C++中BEntry::Remove方法的典型用法代码示例。如果您正苦于以下问题:C++ BEntry::Remove方法的具体用法?C++ BEntry::Remove怎么用?C++ BEntry::Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BEntry
的用法示例。
在下文中一共展示了BEntry::Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
/*
* Given a local directory, do the equivalent of `rm -rf`
* on it, but using the actual filesystem API.
* You can't just use dir->Remove() because that
* gives an error if the directory is not empty.
*/
void
rm_rf(BDirectory *dir)
{
status_t err;
BEntry entry;
err = dir->GetNextEntry(&entry);
while(err==B_OK)
{
BFile file = BFile(&entry, B_READ_ONLY);
if(file.IsDirectory())
{
BDirectory ndir = BDirectory(&entry);
rm_rf(&ndir);
}
err = entry.Remove();
if(err != B_OK)
{
BPath path;
entry.GetPath(&path);
printf("Remove Error: %s on %s\n",strerror(err),path.Path());
//what to do if I can't remove something?
}
err = dir->GetNextEntry(&entry);
}
err = dir->GetEntry(&entry);
err = entry.Remove();
if(err != B_OK)
printf("Folder Removal Error: %s\n", strerror(err));
}
示例2: BString
status_t
RemoveRepositoryJob::Execute()
{
BPackageRoster roster;
BRepositoryConfig repoConfig;
status_t result = roster.GetRepositoryConfig(fRepositoryName, &repoConfig);
if (result != B_OK) {
if (result == B_ENTRY_NOT_FOUND) {
BString error = BString("repository '") << fRepositoryName
<< "' not found!";
SetErrorString(error);
}
return result;
}
BString question = BString("Really remove the repository '")
<< fRepositoryName << "'?";
bool yes = fContext.DecisionProvider().YesNoDecisionNeeded("", question,
"yes", "no", "no");
if (!yes)
return B_CANCELED;
BEntry repoConfigEntry = repoConfig.Entry();
if ((result = repoConfigEntry.Remove()) != B_OK)
return result;
BRepositoryCache repoCache;
if (roster.GetRepositoryCache(fRepositoryName, &repoCache) == B_OK) {
BEntry repoCacheEntry = repoCache.Entry();
if ((result = repoCacheEntry.Remove()) != B_OK)
return result;
}
return B_OK;
}
示例3: if
status_t
InstalledPackageInfo::Uninstall()
{
if (fStatus != B_OK)
return fStatus;
BString *iter;
uint32 i, count = fInstalledItems.CountItems();
BEntry entry;
status_t ret;
// Try to remove all entries that are present in the list
for (i = 0; i < count; i++) {
iter = static_cast<BString *>(fInstalledItems.ItemAt(count - i - 1));
fprintf(stderr, "Removing: %s (%ld/%ld)\n", iter->String(), i, count);
ret = entry.SetTo(iter->String());
if (ret == B_BUSY) {
// The entry's directory is locked - wait a few cycles for it to
// unlock itself
int32 tries = 0;
for (tries = 0; tries < P_BUSY_TRIES; tries++) {
ret = entry.SetTo(iter->String());
if (ret != B_BUSY)
break;
// Wait a moment
usleep(1000);
}
}
if (ret == B_ENTRY_NOT_FOUND)
continue;
else if (ret != B_OK) {
fStatus = B_ERROR;
return fStatus;
}
fprintf(stderr, "...we continue\n");
if (entry.Exists() && entry.Remove() != B_OK) {
fprintf(stderr, "\n%s\n", strerror(ret));
fStatus = B_ERROR;
return fStatus;
}
fInstalledItems.RemoveItem(count - i - 1);
}
if (entry.SetTo(fPathToInfo.Path()) != B_OK) {
fStatus = B_ERROR;
return fStatus;
}
if (entry.Exists() && entry.Remove() != B_OK) {
fStatus = B_ERROR;
return fStatus;
}
return fStatus;
}
示例4:
void
BPackageManager::_CommitPackageChanges(Transaction& transaction)
{
InstalledRepository& installationRepository = transaction.Repository();
fUserInteractionHandler->ProgressStartApplyingChanges(
installationRepository);
// commit the transaction
BCommitTransactionResult transactionResult;
status_t error = fInstallationInterface->CommitTransaction(transaction,
transactionResult);
if (error != B_OK)
DIE(error, "failed to commit transaction");
if (transactionResult.Error() != B_TRANSACTION_OK)
DIE(transactionResult);
fUserInteractionHandler->ProgressTransactionCommitted(
installationRepository, transactionResult);
BEntry transactionDirectoryEntry;
if ((error = transaction.TransactionDirectory()
.GetEntry(&transactionDirectoryEntry)) != B_OK
|| (error = transactionDirectoryEntry.Remove()) != B_OK) {
fUserInteractionHandler->Warn(error,
"failed to remove transaction directory");
}
fUserInteractionHandler->ProgressApplyingChangesDone(
installationRepository);
}
示例5:
static void
close_output_file()
{
if (rdef_err == B_OK || (flags & RDEF_MERGE_RESOURCES) != 0)
rsrc.Sync();
else
entry.Remove(); // throw away output file
file.Unset();
entry.Unset();
}
示例6: _DeleteLogs
void LogPrefsView::_DeleteLogs(BEntry* dir_entry)
{
BEntry entry;
BDirectory dir(dir_entry);
dir.Rewind();
while (dir.GetNextEntry(&entry) == B_OK) {
if (entry.IsDirectory())
_DeleteLogs(&entry);
else
entry.Remove();
}
}
示例7: GetInstallationLocationInfo
status_t
BDaemonClient::CreateTransaction(BPackageInstallationLocation location,
BActivationTransaction& _transaction, BDirectory& _transactionDirectory)
{
// get an info for the location
BInstallationLocationInfo info;
status_t error = GetInstallationLocationInfo(location, info);
if (error != B_OK)
return error;
// open admin directory
entry_ref entryRef;
entryRef.device = info.PackagesDirectoryRef().device;
entryRef.directory = info.PackagesDirectoryRef().node;
error = entryRef.set_name(PACKAGES_DIRECTORY_ADMIN_DIRECTORY);
if (error != B_OK)
return error;
BDirectory adminDirectory;
error = adminDirectory.SetTo(&entryRef);
if (error != B_OK)
return error;
// create a transaction directory
int uniqueId = 1;
BString directoryName;
for (;; uniqueId++) {
directoryName.SetToFormat("transaction-%d", uniqueId);
if (directoryName.IsEmpty())
return B_NO_MEMORY;
error = adminDirectory.CreateDirectory(directoryName,
&_transactionDirectory);
if (error == B_OK)
break;
if (error != B_FILE_EXISTS)
return error;
}
// init the transaction
error = _transaction.SetTo(location, info.ChangeCount(), directoryName);
if (error != B_OK) {
BEntry entry;
_transactionDirectory.GetEntry(&entry);
_transactionDirectory.Unset();
if (entry.InitCheck() == B_OK)
entry.Remove();
return error;
}
return B_OK;
}
示例8: MountImage
// Mounts the specified image file (filename) assuming it contains the
// specified file system.
int app::MountImage(const char *filename, const char *filesystem) {
int timeout=3;
int retvalue;
BString mountpoint;
BEntry entry;
int mountpoint_counter=0;
do {
mountpoint="/";
mountpoint.Append(FindMountPointName(filename));
while (mountpoint[mountpoint.Length()-1]==0x20)
mountpoint.RemoveLast(" ");
if (mountpoint_counter>0)
mountpoint << " " << mountpoint_counter;
entry.SetTo(mountpoint.String());
mountpoint_counter++;
} while(entry.Exists());
CreateDirectory(mountpoint.String());
while ((retvalue=mount(filesystem,mountpoint.String(),filename,2,NULL,0))<0) {
snooze(100000); // omg! ;)
timeout--;
if (timeout==0) {
entry.Remove();
mountpoint_counter--;
entry.Unset();
return -1;
}
};
printf("mounted.\nfilename:\t%s\nfilesystem:\t%s\nmountpoint:\t%s\n", filename, filesystem, mountpoint.String());
if (retvalue<0) {
entry.Remove();
mountpoint_counter--;
}
entry.Unset();
return retvalue;
}
示例9: DeleteDirectory
void PanelView::DeleteDirectory(const char *dirname)
////////////////////////////////////////////////////////////////////////
{
BDirectory *dir;
key_info keyinfo;
// Don't delete the parent directory!!!!!!
if (strlen(dirname)>=3)
{
int len = strlen(dirname);
if (dirname[len-1]=='.' && dirname[len-2]=='.' && dirname[len-3]=='/') return;
}
dir = new BDirectory(dirname);
if (dir)
{
BEntry entry;
if (dir->GetEntry(&entry)==B_OK)
{
while (dir->GetNextEntry(&entry)==B_OK)
{
get_key_info(&keyinfo);
if (keyinfo.key_states[0] & 0x40) // ESC
{
beep();
delete dir;
return;
}
BPath path;
entry.GetPath(&path);
if (entry.IsDirectory())
DeleteDirectory(path.Path());
entry.Remove();
}
}
delete dir;
}
}
示例10: BEntry
void
delete_directory_path(char *path,bool recur)
{
BDirectory *dir;
BPath *pat,pt;
BEntry *ent;
if ((pat = create_path(path)))
{
if ((dir = create_mydir((char *)pat->Path())))
{
if (dir->Rewind() == B_OK)
{
if ((ent = new BEntry()))
{
while (dir->GetNextEntry(ent,false) == B_NO_ERROR)
{
if (ent->GetPath(&pt) == B_NO_ERROR)
{
if (recur)
{
if (ent->IsDirectory())
{
delete_directory_path((char *)pt.Path(),recur);
}
}
}
ent->Remove();
}
delete ent;
}
}
delete dir;
}
delete pat;
}
}
示例11: BInvoker
void
DialUpView::MessageReceived(BMessage *message)
{
switch(message->what) {
case PPP_REPORT_MESSAGE:
HandleReportMessage(message);
break;
// -------------------------------------------------
case kMsgCreateNew: {
(new TextRequestDialog(kLabelCreateNewInterface, kTextChooseInterfaceName,
kLabelInterfaceName))->Go(
new BInvoker(new BMessage(kMsgFinishCreateNew), this));
} break;
case kMsgFinishCreateNew: {
int32 which;
message->FindInt32("which", &which);
const char *name = message->FindString("text");
if(which == 1 && name && strlen(name) > 0)
AddInterface(name, true);
if(fCurrentItem)
fCurrentItem->SetMarked(true);
} break;
// -------------------------------------------------
case kMsgDeleteCurrent: {
if(!fCurrentItem)
return;
fInterfaceMenu->RemoveItem(fCurrentItem);
BDirectory settings, profile;
GetPPPDirectories(&settings, &profile);
BEntry entry;
settings.FindEntry(fCurrentItem->Label(), &entry);
entry.Remove();
profile.FindEntry(fCurrentItem->Label(), &entry);
entry.Remove();
delete fCurrentItem;
fCurrentItem = NULL;
BMenuItem *marked = fInterfaceMenu->FindMarked();
if(marked)
marked->SetMarked(false);
UpdateControls();
SelectInterface(0);
// this stops watching the deleted interface
} break;
case kMsgSelectInterface: {
int32 index;
message->FindInt32("index", &index);
SelectInterface(index);
} break;
case kMsgConnectButton: {
if(!fCurrentItem || fUpDownThread != -1)
return;
fUpDownThread = spawn_thread(up_down_thread, "up_down_thread",
B_NORMAL_PRIORITY, this);
resume_thread(fUpDownThread);
} break;
default:
BView::MessageReceived(message);
}
}
示例12: if
/*
* Given a single line of the output of db_delta.py
* Figures out what to do and does it.
* (adds and removes files and directories)
*/
int
App::parse_command(BString command)
{
command.RemoveAll("\n"); //remove trailing whitespace
if(command.Compare("RESET") == 0)
{
printf("Burn Everything. 8D\n");
status_t err = stop_watching(be_app_messenger);
if(err != B_OK) printf("stop_watching error: %s\n",strerror(err));
BDirectory dir = BDirectory(local_path_string);
rm_rf(&dir);
BString str = BString("/"); //create_local_path wants a remote path
create_local_directory(&str);
this->recursive_watch(&dir);
}
else if(command.Compare("FILE ",5) == 0)
{
BString path, dirpath, partial_path;
BPath *bpath;
int32 last_space = command.FindLast(" ");
command.CopyInto(path,5,last_space - 5);
path.CopyInto(dirpath,0,path.FindLast("/"));
create_local_directory(&dirpath);
//TODO fix watching new dirs
bpath = new BPath(db_to_local_filepath(path.String()).String());
BEntry new_file = BEntry(bpath->Path());
if(new_file.InitCheck() && new_file.Exists()) {
this->new_paths.AddItem((void*)bpath);
} else {
this->edited_paths.AddItem((void*)bpath);
}
printf("create a file at |%s|\n",path.String());
char *argv[3];
argv[0] = "db_get.py";
char not_const1[path.CountChars() + 1];
strcpy(not_const1,path.String());
argv[1] = not_const1;
BString tmp = db_to_local_filepath(path.String());
char not_const2[tmp.CountChars() + 1]; //plus one for null
strcpy(not_const2,tmp.String());
argv[2] = not_const2;
//create/update file
//potential problem: takes awhile to do this step
// having watching for dir turned off is risky.
BString * b = run_python_script(argv,3);
delete b;
//start watching the new/updated file
node_ref nref;
new_file = BEntry(db_to_local_filepath(path.String()).String());
new_file.GetNodeRef(&nref);
status_t err = watch_node(&nref,B_WATCH_STAT,be_app_messenger);
BString parent_rev;
command.CopyInto(parent_rev,last_space + 1, command.CountChars() - (last_space+1));
BNode node = BNode(db_to_local_filepath(path.String()).String());
set_parent_rev(&node,&parent_rev);
}
else if(command.Compare("FOLDER ",7) == 0)
{
BString path;
command.CopyInto(path,7,command.FindLast(" ") - 7);
//ignore the creation message
BPath bpath = BPath(db_to_local_filepath(path.String()).String());
BPath *actually_exists = find_existing_subpath(&bpath);
this->new_paths.AddItem((void*)actually_exists);
//create all nescessary dirs in path
printf("create a folder at |%s|\n", path.String());
create_local_directory(&path);
//start watching the new dir
BDirectory existing_dir = BDirectory(actually_exists->Path());
recursive_watch(&existing_dir);
}
else if(command.Compare("REMOVE ",7) == 0)
{
//TODO: deal with Dropbox file paths being case-insensitive
//which here means all lower case
BString path;
command.CopyInto(path,7,command.Length() - 7);
const char * pathstr = db_to_local_filepath(path.String()).String();
BPath *bpath = new BPath(pathstr);
//TODO: check if it exists...
this->removed_paths.AddItem((void*)bpath);
//.........这里部分代码省略.........
示例13: main
int main(int argc, char *argv[])
{
yyin = stdin;
int i = getoptions(argc, argv);
char buf[PATH_MAX];
if (out[0] == '/')
strcpy(buf, out);
else
{
getcwd(buf, PATH_MAX);
strcat(buf, "/");
strcat(buf, out);
}
BEntry e;
if (e.SetTo(out)) error("entry set to %s", out);
BDirectory d;
if (e.GetParent(&d)) error("get parent of %s", out);
if ((gTruncate || gSaveAsHeader) && e.Exists() && e.Remove())
error("removing %s", out);
BFile f;
BResources res;
if (!gDump)
{
if (gTruncate || !e.Exists())
{
if (d.CreateFile(buf, &f)) error("creating %s", buf);
gTruncate = true;
}
else
if (f.SetTo(buf, B_READ_WRITE)) error("opening %s", buf);
if (gSaveAsHeader)
{
gHeader = fopen(buf, "w");
if (!gHeader) error("Error creating %s", buf);
}
else if (res.SetTo(&f, gTruncate) != B_NO_ERROR)
error("opening resource file %s", buf);
}
resFile = &res;
if (i == argc)
Work(NULL);
else
{
while (i < argc)
Work(in = argv[i++]);
}
if (verbose)
puts("done");
if (gHeader)
fclose(gHeader);
else
f.Sync();
return 0;
} /* main */
示例14: linkName
status_t
PackageLink::WriteToPath(const char *path, ItemState *state)
{
if (state == NULL)
return B_ERROR;
status_t ret = B_OK;
BSymLink symlink;
parser_debug("Symlink: %s WriteToPath() called!\n", fPath.String());
BPath &destination = state->destination;
BDirectory *dir = &state->parent;
if (state->status == B_NO_INIT || destination.InitCheck() != B_OK
|| dir->InitCheck() != B_OK) {
// Not yet initialized
ret = InitPath(path, &destination);
if (ret != B_OK)
return ret;
BString linkName(destination.Leaf());
parser_debug("%s:%s:%s\n", fPath.String(), destination.Path(),
linkName.String());
BPath dirPath;
ret = destination.GetParent(&dirPath);
ret = dir->SetTo(dirPath.Path());
if (ret == B_ENTRY_NOT_FOUND) {
ret = create_directory(dirPath.Path(), kDefaultMode);
if (ret != B_OK) {
parser_debug("create_directory()) failed\n");
return B_ERROR;
}
}
if (ret != B_OK) {
parser_debug("destination InitCheck failed %s for %s\n",
strerror(ret), dirPath.Path());
return ret;
}
ret = dir->CreateSymLink(destination.Path(), fLink.String(), &symlink);
if (ret == B_FILE_EXISTS) {
// We need to check if the existing symlink is pointing at the same path
// as our new one - if not, let's prompt the user
symlink.SetTo(destination.Path());
BPath oldLink;
ret = symlink.MakeLinkedPath(dir, &oldLink);
chdir(dirPath.Path());
if (ret == B_BAD_VALUE || oldLink != fLink.String())
state->status = ret = B_FILE_EXISTS;
else
ret = B_OK;
}
}
if (state->status == B_FILE_EXISTS) {
switch (state->policy) {
case P_EXISTS_OVERWRITE:
{
BEntry entry;
ret = entry.SetTo(destination.Path());
if (ret != B_OK)
return ret;
entry.Remove();
ret = dir->CreateSymLink(destination.Path(), fLink.String(),
&symlink);
break;
}
case P_EXISTS_NONE:
case P_EXISTS_ASK:
ret = B_FILE_EXISTS;
break;
case P_EXISTS_SKIP:
return B_OK;
}
}
if (ret != B_OK) {
parser_debug("CreateSymLink failed\n");
return ret;
}
parser_debug(" Symlink created!\n");
ret = symlink.SetPermissions(static_cast<mode_t>(fMode));
if (fCreationTime && ret == B_OK)
ret = symlink.SetCreationTime(static_cast<time_t>(fCreationTime));
if (fModificationTime && ret == B_OK) {
ret = symlink.SetModificationTime(static_cast<time_t>(
fModificationTime));
}
//.........这里部分代码省略.........
示例15: settings
status_t
TMailApp::SaveSettings()
{
BMailSettings accountSettings;
if (fDefaultAccount != ~0L) {
accountSettings.SetDefaultOutboundAccount(fDefaultAccount);
accountSettings.Save();
}
BPath path;
status_t status = GetSettingsPath(path);
if (status != B_OK)
return status;
path.Append("BeMail Settings~");
BFile file;
status = file.SetTo(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
if (status != B_OK)
return status;
BMessage settings('BeMl');
settings.AddRect("MailWindowSize", fMailWindowFrame);
// settings.AddInt32("ExperienceLevel", level);
font_family fontFamily;
font_style fontStyle;
fContentFont.GetFamilyAndStyle(&fontFamily, &fontStyle);
settings.AddString("FontFamily", fontFamily);
settings.AddString("FontStyle", fontStyle);
settings.AddFloat("FontSize", fContentFont.Size());
settings.AddRect("SignatureWindowSize", fSignatureWindowFrame);
settings.AddBool("WordWrapMode", fWrapMode);
settings.AddPoint("PreferencesWindowLocation", fPrefsWindowPos);
settings.AddBool("AutoMarkRead", fAutoMarkRead);
settings.AddString("SignatureText", fSignature);
settings.AddInt32("CharacterSet", fMailCharacterSet);
settings.AddString("FindString", FindWindow::GetFindString());
settings.AddInt8("ShowButtonBar", fShowToolBar);
settings.AddInt32("UseAccountFrom", fUseAccountFrom);
settings.AddBool("ColoredQuotes", fColoredQuotes);
settings.AddString("ReplyPreamble", fReplyPreamble);
settings.AddBool("AttachAttributes", fAttachAttributes);
settings.AddBool("WarnAboutUnencodableCharacters", fWarnAboutUnencodableCharacters);
settings.AddBool("StartWithSpellCheck", fStartWithSpellCheckOn);
BEntry entry;
status = entry.SetTo(path.Path());
if (status != B_OK)
return status;
status = settings.Flatten(&file);
if (status == B_OK) {
// replace original settings file
status = entry.Rename("BeMail Settings", true);
} else
entry.Remove();
return status;
}