本文整理汇总了C++中DirectoryIterator::ChangeEntry方法的典型用法代码示例。如果您正苦于以下问题:C++ DirectoryIterator::ChangeEntry方法的具体用法?C++ DirectoryIterator::ChangeEntry怎么用?C++ DirectoryIterator::ChangeEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DirectoryIterator
的用法示例。
在下文中一共展示了DirectoryIterator::ChangeEntry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transaction
//.........这里部分代码省略.........
ObjectDeleter<DirectoryIterator> newIteratorDeleter(newIterator);
Vnode vnode(volume, oldID);
Inode* inode;
status = vnode.Get(&inode);
if (status != B_OK)
return status;
uint8 fileType;
// TODO: Support all file types?
if (inode->IsDirectory())
fileType = EXT2_TYPE_DIRECTORY;
else if (inode->IsSymLink())
fileType = EXT2_TYPE_SYMLINK;
else
fileType = EXT2_TYPE_FILE;
// Add entry in destination directory
ino_t existentID;
status = newIterator->FindEntry(newName, &existentID);
if (status == B_OK) {
if (existentID == oldID) {
// Remove entry in oldID
// return inode->Unlink();
return B_BAD_VALUE;
}
Vnode vnodeExistent(volume, existentID);
Inode* existent;
if (vnodeExistent.Get(&existent) != B_OK)
return B_NAME_IN_USE;
if (existent->IsDirectory() != inode->IsDirectory()) {
return existent->IsDirectory() ? B_IS_A_DIRECTORY
: B_NOT_A_DIRECTORY;
}
// TODO: Perhaps we have to revert this in case of error?
status = newIterator->ChangeEntry(transaction, oldID, fileType);
if (status != B_OK)
return status;
notify_entry_removed(volume->ID(), newDirectory->ID(), newName,
existentID);
} else if (status == B_ENTRY_NOT_FOUND) {
newIterator->Restart();
status = newIterator->AddEntry(transaction, newName, strlen(newName),
oldID, fileType);
if (status != B_OK)
return status;
} else
return status;
// Remove entry from source folder
status = oldIterator->RemoveEntry(transaction);
if (status != B_OK)
return status;
inode->WriteLockInTransaction(transaction);
if (oldDirectory != newDirectory && inode->IsDirectory()) {
DirectoryIterator inodeIterator(inode);
status = inodeIterator.FindEntry("..");
if (status == B_ENTRY_NOT_FOUND) {
TRACE("Corrupt file system. Missing \"..\" in directory %"
B_PRIdINO "\n", inode->ID());
return B_BAD_DATA;
} else if (status != B_OK)
return status;
inodeIterator.ChangeEntry(transaction, newDirectory->ID(),
(uint8)EXT2_TYPE_DIRECTORY);
}
status = inode->WriteBack(transaction);
if (status != B_OK)
return status;
entry_cache_remove(volume->ID(), oldDirectory->ID(), oldName);
entry_cache_add(volume->ID(), newDirectory->ID(), newName, oldID);
status = transaction.Done();
if (status != B_OK) {
entry_cache_remove(volume->ID(), oldDirectory->ID(), newName);
entry_cache_add(volume->ID(), newDirectory->ID(), oldName, oldID);
return status;
}
notify_entry_moved(volume->ID(), oldDirectory->ID(), oldName,
newDirectory->ID(), newName, oldID);
return B_OK;
}