Generate SSD tree directory fold from typed Jerboa
ober
93eff4f3742779515bfdc64a02b1547649684072
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -4759,6 +4759,7 @@ trimmedNonBlankLines trimmedNonBlankPathParts mergeJsonLinesTextFromLocalAndRemote validateImportedJsonLinesText + ensureTreePathDirectories ensureTruthStoreDirectories sourceBaseName canonicalSourceName isUsefulGuessLabel isErrorStatus formatActivityDuration groupDisplayLabel appendModeStatus @@ -5780,6 +5781,15 @@ (limit : Int32)) : Bool (and (documentFileIsRegular file) (shouldIncludeSsdPdfChoiceName name currentChoices limit))) + (def (ensureTreePathDirectories + (parent : DocumentFile) + (parts : (List String)) + (ensure : (-> DocumentFile String DocumentFile))) : DocumentFile + (for/fold ((current parent)) + ((i (in-range + (int32 0) + (- (list-size parts) (int32 1))))) + (invoke ensure current (list-ref parts i)))) (def (trimmedNonBlankLines (text : String)) : (MutableList String) (let ((lines (stringLines text))) (for/fold ((out (mutable-list-empty String))) @@ -12126,8 +12136,7 @@ " val parts = trimmedNonBlankPathParts(relativeName, File.separatorChar, '/')" " require(safeTreePathParts(parts, MAX_ZIP_DEPTH))" " val fileName = treePathLeaf(parts)" - " var dir = parent" - " treePathDirectoryParts(parts).forEach { dir = ensureTreeDir(dir, it) }" + " val dir = ensureTreePathDirectories(parent, parts) { current, name -> ensureTreeDir(current, name) }" " deleteDocumentFileIfPresent(dir.findFile(fileName))" " val mime = treeFileMime(fileName)" " val createdFile = dir.createFile(mime, fileName)"