| 467 | } |
| 468 | |
| 469 | U32 KProcess::openFileDescriptor(BString currentDirectory, BString localPath, U32 accessFlags, U32 descriptorFlags, S32 handle, U32 afterHandle, KFileDescriptorPtr& result) { |
| 470 | std::shared_ptr<FsNode> node; |
| 471 | std::shared_ptr<KObject> kobject; |
| 472 | |
| 473 | node = Fs::getNodeFromLocalPath(currentDirectory, localPath, true); |
| 474 | if (!node && (accessFlags & (K_O_CREAT|K_O_TMPFILE))==0) { |
| 475 | return -K_ENOENT; |
| 476 | } |
| 477 | if (accessFlags & K_O_TMPFILE) { |
| 478 | if ((accessFlags & K_O_ACCMODE)!=K_O_WRONLY && (accessFlags & K_O_ACCMODE)!=K_O_RDWR) { |
| 479 | return -K_EINVAL; |
| 480 | } |
| 481 | if (!node || !node->isDirectory()) { |
| 482 | return -K_ENOENT; |
| 483 | } |
| 484 | accessFlags&= ~K_O_TMPFILE; |
| 485 | accessFlags|=K_O_CREAT; |
| 486 | localPath = FsFileNode::getLocalTmpPath(); |
| 487 | node = Fs::getNodeFromLocalPath(currentDirectory, localPath, true); |
| 488 | } else if (node && node->isDirectory()) { |
| 489 | if ((accessFlags & K_O_ACCMODE)!=K_O_RDONLY) { |
| 490 | return -K_EISDIR; |
| 491 | } |
| 492 | } |
| 493 | if (!node) { |
| 494 | BString fullPath = Fs::getFullPath(currentDirectory, localPath); |
| 495 | BString parentPath = Fs::getParentPath(fullPath); |
| 496 | BString fileName = Fs::getFileNameFromPath(fullPath); |
| 497 | std::shared_ptr<FsNode> parent = Fs::getNodeFromLocalPath(B(""), parentPath, true); |
| 498 | if (!parent) { |
| 499 | return -K_ENOENT; |
| 500 | } |
| 501 | BString nativePath = Fs::getNativePathFromParentAndLocalFilename(parent, fileName); |
| 502 | std::shared_ptr<FsNode> mixedSibling = parent->getChildByNameIgnoreCase(fileName); |
| 503 | if (mixedSibling) { |
| 504 | nativePath = nativePath + EXT_MIXED; |
| 505 | if (Fs::doesNativePathExist(nativePath)) { |
| 506 | kwarn("KProcess::openFileDescriptor mixed file already exists"); |
| 507 | } |
| 508 | } |
| 509 | node = Fs::addFileNode(parent->path+"/"+fileName, B(""), nativePath, false, parent); |
| 510 | Fs::makeLocalDirs(parent->path); |
| 511 | } |
| 512 | std::shared_ptr<KObject> nodeObject = node->kobject.lock(); |
| 513 | if (nodeObject) { |
| 514 | kobject = nodeObject; |
| 515 | } else { |
| 516 | FsOpenNode* openNode = node->open(accessFlags); |
| 517 | if (!openNode) { |
| 518 | return translateOpenError(); |
| 519 | } |
| 520 | openNode->openedPath = Fs::getFullPath(currentDirectory, localPath); |
| 521 | kobject = std::make_shared<KFile>(openNode); |
| 522 | } |
| 523 | result = this->allocFileDescriptor(kobject, accessFlags, descriptorFlags, handle, afterHandle); |
| 524 | return 0; |
| 525 | } |
| 526 |
no test coverage detected