summaryrefslogtreecommitdiff
path: root/gentoobrowse/console/fileimport.xml
blob: b65573fde120c8bbd2836628d968cb631116ea89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?xml version="1.0"?>
<packageimport name="bugassociate" xmlns:xi="http://www.w3.org/2001/XInclude"
		xmlns:project2="http://project2.randomdan.homeip.net">
	<xi:include href="../datasources/postgres.xml" />
	<project2:sqlrows name="fileTypes" datasource="postgres">
		<sql>
			SELECT filetypeid, searchroot, LENGTH(searchroot) + 1 || '-' AS rootlen, searchspec
			FROM filetypes
			ORDER BY filetypeid DESC
		</sql>
	</project2:sqlrows>
	<project2:procrows name="findCacheFiles" newline="&#10;" encoding="ascii" fieldSep="|" quoteChar=""
			path="*find ^searchroot ^searchspec -printf &quot;%p|%t\n&quot; | cut -b ^rootlen | sed &apos;s#^# ^filetypeid |#&apos;" >
		<columns>
			<column>filetypeid</column>
			<column>filename</column>
			<column>moddate</column>
		</columns>
	</project2:procrows>

	<project2:sqlmerge name="files" datasource="postgres" targettable="files">
		<project2:iterate name="eachFileType" source="fileTypes">
			<project2:iterate name="eachCacheFile" source="findCacheFiles" />
		</project2:iterate>
		<columns>
			<column key="true">filename</column>
			<column>moddate</column>
			<column>filetypeid</column>
		</columns>
	</project2:sqlmerge>

	<project2:sqlrows name="outDatedFiles" datasource="postgres">
		<sql>
			SELECT f.fileid, ft.searchroot || f.filename AS filename, f.cachedat, f.moddate
			FROM files f, filetypes ft
			WHERE (f.cachedat IS NULL OR f.cachedat != f.moddate)
			AND f.filetypeid = ft.filetypeid
			ORDER BY f.fileid
		</sql>
	</project2:sqlrows>
	<project2:procrows name="readFileContent" newline="&#10;" encoding="utf-8" fieldSep="|" quoteChar=""
			path="*grep -n . ^filename | sed -e &apos;s#:#|#&apos; -e &apos;s#^# ^fileid |#&apos;" >
		<columns>
			<column>fileid</column>
			<column>line</column>
			<column>content</column>
		</columns>
	</project2:procrows>

	<project2:sqlmerge name="loadCacheContent" datasource="postgres" targettable="filecache"
			updatewhere="*a.fileid IN (SELECT o.fileid FROM files o WHERE o.cachedat IS NULL OR o.cachedat != o.moddate)">
		<project2:iterate name="eachOutDatedFile" source="outDatedFiles">
			<project2:iterate name="eachFileContent" source="readFileContent" />
		</project2:iterate>
		<columns>
			<column key="true">fileid</column>
			<column key="true">line</column>
			<column>content</column>
		</columns>
	</project2:sqlmerge>

	<project2:sqltask name="setCachedTime" datasource="postgres">
		<sql>UPDATE files SET cachedat = moddate WHERE cachedat != moddate OR cachedat IS NULL</sql>
	</project2:sqltask>
</packageimport>