mirror of
https://github.com/tiennm99/telegram-exporter.git
synced 2026-10-11 03:13:49 +00:00
rclone does not address a file by the bytes os.OpenFile wrote. Names handed to an Fs go through the backend encoder and names listed back are re-encoded to the standard set, neither of which the write path performs. A filename holding one of the rewritten characters was therefore stored under one string and looked up under another: confirmed against the local backend, where a written "a‛b.jpg" reports object not found and a written "a\nb.jpg" lists back as "a␊b.jpg". That is the same two-derivation divergence this program was written to remove, with rclone's encoder standing where filenamify used to. Such names are rejected, not encoded, for the same reason every other name is. The length limit ignored the ".part" suffix that is opened first, so a name just inside NAME_MAX passed the check and then failed to open on every pass, stalling the walk on that message forever. The suffix now lives beside the limit that has to account for it. filter.NewFilter(nil) does not build a neutral filter; it copies the package global, which rclone has already filled from RCLONE_*. Indexing inherited the operator's environment, so a stray RCLONE_MIN_SIZE emptied the index and re-downloaded the archive. Every narrowing field is now set explicitly and the result is asserted inactive. A subprocess test covers it, since the env is read at package init and t.Setenv is too late to observe anything. An ErrorDirNotFound from a subdirectory was also treated as an empty destination, returning a partial index as authoritative. t.me/c/<id> and t.me/s/<name> were passed through whole, and gotd reads the first path component as the username — resolving "c" or "s", which is a confusing failure at best and someone else's chat at worst, since one-character usernames exist. Both now yield the chat, and t.me/s/<name>/<id> is refused like any other message link. Two tests asserted the old behaviour. core's dcpool.Takeout deadlocks when takeout init fails: it holds the pool mutex and recovers by calling Client, which takes the same non-reentrant mutex. Telegram returns TAKEOUT_INIT_DELAY for a takeout started recently and takeout is on by default, so two runs in succession hang the process with no output and no response to cancellation. The session is established once here instead, falling back to a plain client, and the pool's own Takeout is never called.
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package remote
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
_ "github.com/rclone/rclone/backend/local"
|
|
"github.com/rclone/rclone/fs"
|
|
)
|
|
|
|
// rclone reads RCLONE_* into its global config at package init, so an in-process
|
|
// t.Setenv is too late to prove anything. A subprocess is the only way to
|
|
// observe what BuildIndex actually does under an operator's environment — which
|
|
// is exactly why the original no-op neutralisation went unnoticed.
|
|
func TestBuildIndexIgnoresInheritedFilters(t *testing.T) {
|
|
if os.Getenv("GO_INDEX_ENV_CHILD") == "1" {
|
|
indexChild(t)
|
|
return
|
|
}
|
|
for _, env := range []string{
|
|
"RCLONE_EXCLUDE=*.mp4",
|
|
"RCLONE_FILTER=- *.mp4",
|
|
"RCLONE_MIN_SIZE=1M",
|
|
"RCLONE_MAX_AGE=1h",
|
|
"RCLONE_MAX_DEPTH=1",
|
|
} {
|
|
t.Run(env, func(t *testing.T) {
|
|
cmd := exec.Command(os.Args[0], "-test.run=TestBuildIndexIgnoresInheritedFilters", "-test.v")
|
|
cmd.Env = append(os.Environ(), "GO_INDEX_ENV_CHILD=1", env)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Errorf("%s narrowed the index:\n%s", env, out)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func indexChild(t *testing.T) {
|
|
dir := t.TempDir()
|
|
for _, rel := range []string{"a.mp4", "b.txt", "sub/c.mp4"} {
|
|
p := filepath.Join(dir, rel)
|
|
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(p, []byte("x"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
f, err := fs.NewFs(t.Context(), dir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
idx, err := BuildIndex(t.Context(), f, 1234567890)
|
|
if err != nil {
|
|
t.Fatalf("BuildIndex: %v", err)
|
|
}
|
|
for _, want := range []string{"a.mp4", "b.txt", "c.mp4"} {
|
|
if _, ok := idx.Lookup(want); !ok {
|
|
t.Errorf("%q missing from the index", want)
|
|
}
|
|
}
|
|
}
|