Files
filebrowser/backend/pkg/indexing/created_time_linux_test.go
T
+5 8f2e8add9a Beta/v2.1.1 (#3109)
Co-authored-by: Kevin B. <kurami32_kbm@proton.me>
Co-authored-by: spatiumstas <79056064+spatiumstas@users.noreply.github.com>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Andreas Fehn <fehnomenal@fehn.systems>
Co-authored-by: Matt Van Horn <mvanhorn@users.noreply.github.com>
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Takahiro Shimizu <anatofuz@gmail.com>
Co-authored-by: Graham Steffaniak <gtsteffaniak@users.noreply.github.com>
Co-authored-by: Joel Town Road <13539685+hippi345@users.noreply.github.com>
Co-authored-by: beemines <3083452174@qq.com>
Co-authored-by: Bee mines <Beemines82@gmail.com>
Co-authored-by: dweebzxx <134675545+dweebzxx@users.noreply.github.com>
Co-authored-by: Stephan Paternotte <Stephan-P@users.noreply.github.com>
2026-10-09 19:18:51 -05:00

57 lines
1.5 KiB
Go

//go:build linux
package indexing
import (
"os"
"path/filepath"
"testing"
"time"
)
// TestGetCreatedTime_Symlink checks that the reported birth time follows the supplied
// FileInfo: the link's own time for Lstat info, the target's time for Stat info.
func TestGetCreatedTime_Symlink(t *testing.T) {
dir := t.TempDir()
target := filepath.Join(dir, "target.txt")
link := filepath.Join(dir, "link")
if err := os.WriteFile(target, []byte("hello"), 0o644); err != nil {
t.Fatal(err)
}
// Ensure the link's birth time differs from the target's.
time.Sleep(50 * time.Millisecond)
if err := os.Symlink(target, link); err != nil {
t.Fatal(err)
}
targetInfo, err := os.Stat(target)
if err != nil {
t.Fatal(err)
}
linkInfo, err := os.Lstat(link)
if err != nil {
t.Fatal(err)
}
followedInfo, err := os.Stat(link)
if err != nil {
t.Fatal(err)
}
targetCreated := getCreatedTime(targetInfo, target)
linkCreated := getCreatedTime(linkInfo, link)
if targetCreated == nil || linkCreated == nil {
t.Skip("filesystem does not report birth time")
}
if !linkCreated.After(*targetCreated) {
t.Skipf("filesystem birth times are too coarse to distinguish link (%v) from target (%v)", linkCreated, targetCreated)
}
if got := getCreatedTime(linkInfo, link); got == nil || !got.Equal(*linkCreated) {
t.Errorf("Lstat info: got %v, want link birth time %v", got, linkCreated)
}
if got := getCreatedTime(followedInfo, link); got == nil || !got.Equal(*targetCreated) {
t.Errorf("Stat info: got %v, want target birth time %v", got, targetCreated)
}
}