1 ! Copyright (C) 2010 Joe Groff.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: globs io.directories io.files.info io.pathnames kernel
4 regexp sequences sets vocabs.loader vocabs.metadata ;
5 IN: vocabs.metadata.resources
9 : copy-vocab-resource ( to from file -- )
10 [ append-path ] curry bi@
11 dup file-info directory?
12 [ drop make-directories ]
13 [ swap make-parent-directories copy-file ] if ;
17 : vocab-dir-in-root ( vocab -- dir )
18 vocab-source-path parent-directory ;
20 : expand-resource ( resource-path -- filenames )
21 dup dup file-info directory? [
22 recursive-directory-files
27 ERROR: resource-missing pattern ;
29 : match-pattern ( pattern filenames -- filenames' )
30 over <glob> '[ _ matches? ] filter
31 [ resource-missing ] [ nip ] if-empty ;
33 : match-patterns ( patterns filenames -- filenames' )
34 '[ _ match-pattern ] gather ;
36 : vocab-resource-files ( vocab -- filenames )
38 swap vocab-dir-in-root
40 match-patterns [ expand-resource ] map concat
41 ] with-directory-files
44 : copy-vocab-resources ( dir vocab -- )
45 dup vocab-resource-files
47 [ [ vocab-dir append-path ] [ vocab-dir-in-root ] bi ] dip
48 [ 2drop make-directories ]
49 [ [ copy-vocab-resource ] 2with each ] 3bi