author | Mikael Berthe <mikael@lilotux.net> |
Sun, 14 Oct 2018 13:20:09 +0200 | |
changeset 36 | e918b7e63748 |
parent 18 | 5219596f5c71 |
permissions | -rw-r--r-- |
18
5219596f5c71
Change comments so that build constraints still work
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
1 |
// |
5219596f5c71
Change comments so that build constraints still work
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
2 |
// Copyright (C) 2014 Mikael Berthe <mikael@lilotux.net> |
5219596f5c71
Change comments so that build constraints still work
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
3 |
// |
5219596f5c71
Change comments so that build constraints still work
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
4 |
// This program is free software; you can redistribute it and/or modify |
5219596f5c71
Change comments so that build constraints still work
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
5 |
// it under the terms of the GNU General Public License as published by |
5219596f5c71
Change comments so that build constraints still work
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
6 |
// the Free Software Foundation; either version 2 of the License, or (at |
5219596f5c71
Change comments so that build constraints still work
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
7 |
// your option) any later version. |
0
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
8 |
|
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
9 |
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
10 |
|
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
11 |
package main |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
12 |
|
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
13 |
import "os" |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
14 |
import "syscall" |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
15 |
|
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
16 |
// ByInode is a FileObjList type with a sort interface |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
17 |
type ByInode FileObjList |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
18 |
|
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
19 |
func (a ByInode) Len() int { return len(a) } |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
20 |
func (a ByInode) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
21 |
func (a ByInode) Less(i, j int) bool { |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
22 |
// Sort by device id first |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
23 |
iDevice := a[i].Sys().(*syscall.Stat_t).Dev |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
24 |
jDevice := a[j].Sys().(*syscall.Stat_t).Dev |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
25 |
switch { |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
26 |
case iDevice < jDevice: |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
27 |
return true |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
28 |
case iDevice > jDevice: |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
29 |
return false |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
30 |
} |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
31 |
iInode := a[i].Sys().(*syscall.Stat_t).Ino |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
32 |
jInode := a[j].Sys().(*syscall.Stat_t).Ino |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
33 |
return iInode < jInode |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
34 |
} |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
35 |
|
3
d08d45871171
Add descriptions to exported functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
36 |
// OSHasInodes returns true iff the O.S. uses inodes for its filesystems. |
0
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
37 |
func OSHasInodes() bool { |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
38 |
return true |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
39 |
} |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
40 |
|
3
d08d45871171
Add descriptions to exported functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
41 |
// GetDevIno returns the device and inode IDs of a given file. |
0
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
42 |
func GetDevIno(fi os.FileInfo) (uint64, uint64) { |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
43 |
dev := fi.Sys().(*syscall.Stat_t).Dev |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
44 |
ino := fi.Sys().(*syscall.Stat_t).Ino |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
45 |
return uint64(dev), uint64(ino) |
a5642cd03cef
Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
46 |
} |