<commit_before>package reverse

import (
	"io/ioutil"
	"net/url"
	"os"
	"runtime"
	"syscall"
	"testing"

	"github.com/rfjakob/gocryptfs/tests/test_helpers"
)

func doTestOneFileSystem(t *testing.T, plaintextnames bool) {
	// Let's not explode with "TempDir: pattern contains path separator"
	myEscapedName := url.PathEscape(t.Name())
	mnt, err := ioutil.TempDir(test_helpers.TmpDir, myEscapedName)
	if err != nil {
		t.Fatal(err)
	}
	cliArgs := []string{"-reverse", "-zerokey", "-one-file-system"}
	if plaintextnames {
		cliArgs = append(cliArgs, "-plaintextnames")
	}
	test_helpers.MountOrFatal(t, "/", mnt, cliArgs...)
	defer test_helpers.UnmountErr(mnt)

	// Copied from inomap
	const maxPassthruIno = 1<<48 - 1

	entries, err := os.ReadDir(mnt)
	if err != nil {
		t.Fatal(err)
	}
	mountpoints := []string{}
	for _, e := range entries {
		i, err := e.Info()
		if err != nil {
			continue
		}
		if !e.IsDir() {
			// We are only interested in directories
			continue
		}
		st := i.Sys().(*syscall.Stat_t)
		// The inode numbers of files with a different device number are remapped
		// to something above maxPassthruIno
		if st.Ino > maxPassthruIno {
			mountpoints = append(mountpoints, e.Name())
		}
	}
	if len(mountpoints) == 0 {
		t.Skip("no mountpoints found, nothing to test")
	}
	for _, m := range mountpoints {
		e, err := os.ReadDir(mnt + "/" + m)
		if err != nil {
			t.Error(err)
		}
		expected := 1
		if plaintextnames {<commit_msg>tests/reverse: replace os.ReadDir to support older Go versions<commit_after>package reverse

import (
	"io/ioutil"
	"net/url"
	"runtime"
	"syscall"
	"testing"

	"github.com/rfjakob/gocryptfs/tests/test_helpers"
)

func doTestOneFileSystem(t *testing.T, plaintextnames bool) {
	// Let's not explode with "TempDir: pattern contains path separator"
	myEscapedName := url.PathEscape(t.Name())
	mnt, err := ioutil.TempDir(test_helpers.TmpDir, myEscapedName)
	if err != nil {
		t.Fatal(err)
	}
	cliArgs := []string{"-reverse", "-zerokey", "-one-file-system"}
	if plaintextnames {
		cliArgs = append(cliArgs, "-plaintextnames")
	}
	test_helpers.MountOrFatal(t, "/", mnt, cliArgs...)
	defer test_helpers.UnmountErr(mnt)

	// Copied from inomap
	const maxPassthruIno = 1<<48 - 1

	entries, err := ioutil.ReadDir(mnt)
	if err != nil {
		t.Fatal(err)
	}
	mountpoints := []string{}
	for _, e := range entries {
		if !e.IsDir() {
			// We are only interested in directories
			continue
		}
		st := e.Sys().(*syscall.Stat_t)
		// The inode numbers of files with a different device number are remapped
		// to something above maxPassthruIno
		if st.Ino > maxPassthruIno {
			mountpoints = append(mountpoints, e.Name())
		}
	}
	if len(mountpoints) == 0 {
		t.Skip("no mountpoints found, nothing to test")
	}
	for _, m := range mountpoints {
		e, err := ioutil.ReadDir(mnt + "/" + m)
		if err != nil {
			t.Error(err)
		}
		expected := 1
		if plaintextnames {
{'fraction_non_alphanumeric': 0.1450831024930748, 'fraction_numerical': 0.004155124653739612, 'mean_word_length': 3.578446909667195, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '114616', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1093, 'n_words': 265}