Is there a way to create a file and its directory if missing?
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- swift
- Área
- operating-systems
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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?
- Lenguaje dominante
- Swift
- Estrellas
- 959
- Forks
- 40
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de mxcl/Path.swift
-
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
mxcl/Path.swift#88 · 2 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
mxcl/Path.swift#66 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
mxcl/Path.swift#17 · 1 comentario ·
Todos los issues de mxcl/Path.swift
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
Los mantenedores suelen responder en 1 día
-
test(BrainBar): inject synthetic observabilityCadence in BackupsHealth/one-page fixtures (DCI-1)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
EtanHey/brainlayer#1367 ·
Los mantenedores suelen responder en 1 día
-
cmux-next: new workspaces show no name instead of workspace-NPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoarea: workspaces
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
manaflow-ai/cmux#21357 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 4 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100