goduf-byinode_fallback.go
author Mikael Berthe <mikael@lilotux.net>
Wed, 23 Feb 2022 22:56:53 +0100
changeset 45 ea6a9ba7a3c8
parent 18 5219596f5c71
permissions -rw-r--r--
Display existing hard links in result sets This is a breaking change in the plain text output, but somehow the list displayed in case of existing hard links was arbitrary, since the all the hardlinked filenames were not displayed. Here's a sample JSON result with this patch: { "file_size": 9216, "paths": [ "test_tree/f09-1_5.raw", "test_tree/f09-4_5.raw" ], "links": { "test_tree/f09-1_5.raw": [ "test_tree/f09-2_5.raw", "test_tree/f09-3_5.raw" ], "test_tree/f09-4_5.raw": [ "test_tree/f09-5_5.raw" ] } } Here the 5 files have the same contents, but there are two hardlink groups: "test_tree/f09-1_5.raw" "test_tree/f09-2_5.raw" "test_tree/f09-3_5.raw" are hard-linked, and "test_tree/f09-4_5.raw" "test_tree/f09-5_5.raw" are hard-linked. Here's the same set displayed With the regular text output: Group #5 (2 files * 9216 bytes): test_tree/f09-1_5.raw test_tree/f09-2_5.raw test_tree/f09-3_5.raw test_tree/f09-4_5.raw test_tree/f09-5_5.raw (The link file names are indented using 1 space character.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 plan9 windows
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
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
// ByInode is a FileObjList type with a sort interface
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
type ByInode FileObjList
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    18
func (a ByInode) Len() int      { return len(a) }
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    19
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
    20
func (a ByInode) Less(i, j int) bool {
11
47e45453b705 Sort files by path when sorting by inode number is not supported
Mikael Berthe <mikael@lilotux.net>
parents: 3
diff changeset
    21
	return a[i].FilePath < a[j].FilePath
0
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    22
}
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
3
d08d45871171 Add descriptions to exported functions
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    24
// 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
    25
func OSHasInodes() bool {
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
	return false
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
}
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
3
d08d45871171 Add descriptions to exported functions
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    29
// GetDevIno returns the device and inode IDs of a given file.
d08d45871171 Add descriptions to exported functions
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    30
// This is not supported on Windows and Plan9.
0
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    31
func GetDevIno(fi os.FileInfo) (uint64, uint64) {
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    32
	return 0, 0 // Not supported
a5642cd03cef Goduf - initial version-controlled revision
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    33
}