File: move7

package info (click to toggle)
apt-move 4.2.27-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 524 kB
  • sloc: sh: 7,946; awk: 275; cpp: 235; perl: 170; makefile: 69
file content (108 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download | duplicates (8)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# $Id: move7,v 1.5 2002/10/07 09:39:07 herbert Exp $

function read(file) {
	err = getline < file
	if (err < 0) {
		print "getline failed on " file > "/dev/stderr"
		exit 1
	} else if (err == 0) {
		eof = 1
		return
	}

	curname = $1
	curfile = $2
	curver = $3
}

function process(dir, i, a) {
	if (best == "") {
		return
	}

	if (!eof && curname == name) {
		print "1 u " curfile
	}

	dir = bestlink
	sub(/\/[^\/]*$/, "", dir)
	print "2\tD " dir
	print "3\tl " bestfile " " bestlink

	split(besttail, a)
	for (i in a) {
		usecnt[a[i]] = 1
	}
}

function moveskip(i) {
	for (i in usecnt) {
		if (usecnt[i]) {
			print i > movef
		} else {
			print i > skipf
		}
	}
}

BEGIN {
	curf = ARGV[1]
	skipf = ARGV[2]
	movef = ARGV[3]
	ARGC = 1

	read(curf)
	printf "" > skipf
	printf "" > movef
}

{
	name = $1
	split($1, a, /\//)
	key = a[1]
}

prevname != name {
	process()
	best = ""
}

prevkey != key {
	moveskip()
	split("", usecnt)
	prevkey = key
}

{
	link = $2
	ver = $3
	file = $4
	tail = ""
	for (i = 5; i <= NF; i++) {
		tail = tail " " $i
		usecnt[$i] += 0
	}
}

prevname != name {
	while (!eof && curname < name) {
		read(curf)
	}
	prevname = name
}

!eof && curname == name && cmpversion(ver, curver) <= 0 {
	next
}

best == "" || cmpversion(ver, best) > 0 {
	best = ver
	bestlink = link
	bestfile = file
	besttail = tail
}

END {
	process()
	moveskip()
}