Is there a way to create a file and its directory if missing?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- swift
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Start by reading the Path.touch(), Path.mkdir(), and parent APIs referenced in the issue. Decide whether recursive parent creation belongs in touch or a separate API, then verify the chosen behavior when one or more parent directories are missing and when they already exist.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Currently, path.touch() fails if path.parent, path.parent.parent, and so on doesn't exist.
Currently, my workaround is as such:
/// Get the missing parent directories of a path, shallow to deep.
/// - Parameter path: The path to get the missing parent directories of.
/// - Returns: An array of the missing parent directories.
func getMissingParentDirectories(of path: Path) -> [Path] {
var missingParentDirectories: [Path] = []
var currentPath = path.parent
while !currentPath.exists {
missingParentDirectories.append(currentPath)
currentPath = currentPath.parent
}
return missingParentDirectories.reversed()
}
/// Create the missing parent directories of a path, shallow to deep.
/// - Parameter path: The path to create the missing parent directories of.
func createMissingParentDirectories(of path: Path) {
let missingParentDirectories = getMissingParentDirectories(of: path)
for missingParentDirectory in missingParentDirectories {
do {
try missingParentDirectory.mkdir()
} catch {
fatalError("Could not create the directory \(missingParentDirectory)")
}
}
}
Is there a native way to do this that I am missing?
- Ngôn ngữ chính
- Swift
- Star
- 959
- Fork
- 40
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mxcl/Path.swift
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
mxcl/Path.swift#88 · 2 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
mxcl/Path.swift#66 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
mxcl/Path.swift#17 · 1 bình luận ·
Tất cả issue của mxcl/Path.swift
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
mozilla-mobile/firefox-ios#35996 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix: pre-push hook이 worktree에서 GIT_DIR을 상속해 SwiftPM 패키지 해석에 실패Có thể đã có người làm @zaehorang đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 85/100
pluk-inc/markdown-preview#493 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Reading an empty file leaks a 4 KB buffer on Linux (Data(contentsOf:), String(contentsOfFile:))Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
swiftlang/swift-foundation#2304 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:caching bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
axeslasher/Jelly-Shark#321 ·
Maintainer thường phản hồi trong vòng 1 ngày