FileCollection.dcl 1.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
definition module iTasks.Extensions.FileCollection
/**
* This extension provides a set of SDS functions to map
* somewhat complex data structures to a directory tree structure with text files on disk.
*/
import iTasks
from Data.Map import :: Map
from System.FilePath import :: FilePath

//Determine if a path is part of the colleciton based on the relative path and whether it is a directory 
:: FileFilter :== FilePath Bool -> Bool

:: FileCollection :== Map String FileCollectionItem
:: FileCollectionItem
	= FileContent String 
	| FileCollection FileCollection

derive class iTask FileCollectionItem

20 21 22 23 24 25 26 27
/**
* Writes a map of key/value pairs to a directory with one file per key/value
* It will ignore all files in the directory that don't match the filter

* @param The filter that specifies which files and directories are part of the collection
* @param Delete flag: When this is true, files on disk that are not in the collection, but match the filter are deleted during a write.
                      If it is false, entries on that are removed are only marked in a file called 'exclude.txt' but not deleted.
*/
Haye Böhm's avatar
Fix CI  
Haye Böhm committed
28
fileCollection :: FileFilter Bool -> SDSSource FilePath FileCollection FileCollection
29 30 31 32 33 34 35 36 37

//Access utilities:
getStringContent:: String FileCollection -> Maybe String
setStringContent:: String String FileCollection -> FileCollection

getIntContent :: String FileCollection -> Maybe Int
setIntContent :: String Int FileCollection -> FileCollection

toPaths :: FileCollection -> [FilePath]
38 39 40

//Filter to ignore all hidden files (e.g. starting with a '.')
ignoreHiddenFiles :: FileFilter