Esempio n. 1
0
/*
 * Holy moly, what a mess!
 */
func LoadAvailableManpages(basedir string) map[int][]string {
	availablePages := make(map[int][]string)

	sectionDirs, err := ioutil.ReadDir(basedir)
	if err != nil {
		log.Print(err)
	}
	for _, sectionDir := range sectionDirs {
		if sectionDir.IsDir() {
			sectionDirPath := path.Join(basedir, sectionDir.Name())
			files, err := ioutil.ReadDir(sectionDirPath)
			if err != nil {
				log.Print(err)
			}
			sectionNumber, err := strconv.Atoi(sectionDir.Name()[len(sectionDir.Name())-1:])
			if err != nil {
				log.Print(err)
			}
			for _, file := range files {
				if !file.IsDir() && strings.HasSuffix(file.Name(), ".html") {
					if _, ok := availablePages[sectionNumber]; !ok {
						availablePages[sectionNumber] = []string{}
					}
					availablePages[sectionNumber] = append(
						availablePages[sectionNumber],
						path.Join(sectionDirPath, file.Name()))
				}
			}

		}
	}
	return availablePages
}
Esempio n. 2
0
func suggestPaths(tok string) (cnt int) {
	root, base := path.Split(tok)
	if isDir(tok) {
		root, base = tok, ""
	}

	fis, _ := ioutil.ReadDir(root)
	if root == "" {
		fis, _ = ioutil.ReadDir(".")
	}

	for _, fi := range fis {
		if strings.Index(fi.Name(), base) != 0 {
			// Skip paths don't match the partial token
			continue
		}
		if strings.Index(fi.Name(), ".") == 0 && len(base) == 0 {
			// Skip hidden folders unless there is a partial match
			continue
		}
		if fi.IsDir() {
			fmt.Println(root + fi.Name() + string(os.PathSeparator))
			cnt++
		} else {
			fmt.Println(root + fi.Name() + " ")
			cnt++
		}
	}
	return cnt
}
Esempio n. 3
0
// Mounted shows any volumes that belong to volplugin on the host, in
// their native representation. They yield a *Mount.
func (d *Driver) Mounted(time.Duration) ([]*storage.Mount, error) {
	mounts := []*storage.Mount{}
	fis, err := ioutil.ReadDir(d.mountpath)
	if os.IsNotExist(err) {
		return mounts, os.MkdirAll(d.mountpath, 0700)
	} else if err != nil {
		return nil, errored.Errorf("Reading policy tree for mounts").Combine(err)
	}

	for _, fi := range fis {
		volumes, err := ioutil.ReadDir(filepath.Join(d.mountpath, fi.Name()))
		if err != nil {
			return nil, errored.Errorf("Reading mounted volumes for policy %q", fi.Name()).Combine(err)
		}

		for _, vol := range volumes {
			rel := filepath.Join(d.mountpath, fi.Name(), vol.Name())
			if err != nil {
				return nil, errored.Errorf("Calculating mount information for %q/%q", fi.Name(), vol.Name()).Combine(err)
			}

			mounts = append(mounts, &storage.Mount{
				Path: rel,
				Volume: storage.Volume{
					Name:   rel,
					Source: "null",
				},
			})
		}
	}

	return mounts, nil
}
Esempio n. 4
0
func deleteEmptyFoldersImpl(root string, level int) error {
	fis, err := ioutil.ReadDir(root)
	if err != nil {
		return err
	}

	foundPlain := false

	for _, sfi := range fis {
		if sfi.IsDir() {
			err = deleteEmptyFoldersImpl(filepath.Join(root, sfi.Name()), level+1)
			if err != nil {
				return err
			}
		} else {
			foundPlain = true
		}
	}

	if !foundPlain && level > 0 {
		fis, err = ioutil.ReadDir(root)
		if err != nil {
			return err
		}

		if len(fis) == 0 {
			err = os.Remove(root)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Esempio n. 5
0
func checkDirectory(dir string, expected map[string]string) error {
	list, err := ioutil.ReadDir(dir)
	if err != nil {
		return err
	}
	for _, fi := range list {
		if !fi.IsDir() {
			return fmt.Errorf("%s is not a directory", fi.Name())
		}
		dirName := fi.Name()
		if _, err := strconv.Atoi(dirName); err != nil {
			return fmt.Errorf("Name is not a number: %v", err)
		}
		expectedFileName, ok := expected[dirName]
		if !ok {
			return fmt.Errorf("Unexpected name found: %s", dirName)
		}
		subList, err := ioutil.ReadDir(filepath.Join(dir, dirName))
		if err != nil {
			return fmt.Errorf("Failed to get a list of files in %s: %v",
				dirName, err)
		}
		filesCount := len(subList)
		if filesCount != 1 {
			return fmt.Errorf("Expected only 1 file in %s, got %d",
				dirName, filesCount)
		}
		gottenFileName := subList[0].Name()
		if gottenFileName != expectedFileName {
			return fmt.Errorf("Expected %s in %s, got %s",
				expectedFileName, dirName, gottenFileName)
		}
	}
	return nil
}
Esempio n. 6
0
func TestKeyReadWriterMigrate(t *testing.T) {
	cert, key, err := testutils.CreateRootCertAndKey("cn")
	require.NoError(t, err)

	tempdir, err := ioutil.TempDir("", "KeyReadWriter")
	require.NoError(t, err)
	defer os.RemoveAll(tempdir)

	path := ca.NewConfigPaths(filepath.Join(tempdir))

	// if the key exists in an old location, migrate it from there.
	tempKeyPath := filepath.Join(filepath.Dir(path.Node.Key), "."+filepath.Base(path.Node.Key))
	require.NoError(t, ioutil.WriteFile(path.Node.Cert, cert, 0644))
	require.NoError(t, ioutil.WriteFile(tempKeyPath, key, 0600))

	krw := ca.NewKeyReadWriter(path.Node, nil, nil)
	require.NoError(t, krw.Migrate())
	_, err = os.Stat(tempKeyPath)
	require.True(t, os.IsNotExist(err)) // it's been moved to the right place
	_, _, err = krw.Read()
	require.NoError(t, err)

	// migrate does not affect any existing files
	dirList, err := ioutil.ReadDir(filepath.Dir(path.Node.Key))
	require.NoError(t, err)
	require.NoError(t, krw.Migrate())
	dirList2, err := ioutil.ReadDir(filepath.Dir(path.Node.Key))
	require.NoError(t, err)
	require.Equal(t, dirList, dirList2)
	_, _, err = krw.Read()
	require.NoError(t, err)
}
Esempio n. 7
0
func TestUnionFsFdLeak(t *testing.T) {
	beforeEntries, err := ioutil.ReadDir("/proc/self/fd")
	if err != nil {
		t.Fatalf("ReadDir failed: %v", err)
	}

	wd, clean := setupUfs(t)
	err = ioutil.WriteFile(wd+"/ro/file", []byte("blablabla"), 0644)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}
	setRecursiveWritable(t, wd+"/ro", false)

	contents, err := ioutil.ReadFile(wd + "/mnt/file")
	if err != nil {
		t.Fatalf("ReadFile failed: %v", err)
	}

	err = ioutil.WriteFile(wd+"/mnt/file", contents, 0644)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}

	clean()

	afterEntries, err := ioutil.ReadDir("/proc/self/fd")
	if err != nil {
		t.Fatalf("ReadDir failed: %v", err)
	}

	if len(afterEntries) != len(beforeEntries) {
		t.Errorf("/proc/self/fd changed size: after %v before %v", len(beforeEntries), len(afterEntries))
	}
}
// DirectoryContents returns a two-dimensional slice with full-path directories
// to send to dupl for evaluation. The first index addresses the specific lab,
// and the second index addresses the specific student. If a student does not
// have the lab directory, the 2D slice will save the directory as an empty
// string. The second return argument indicates whether or not the function was
// successful. DirectoryContents takes as input baseDir, the location of the
// student directories, and labs, a slice of the labs.
func DirectoryContents(baseDir string, labs []LabInfo) ([][]string, bool) {
	// Try to read the base directory
	contents, err := ioutil.ReadDir(baseDir)
	if err != nil {
		fmt.Printf("Error reading directory %s: %s\n", baseDir, err)
		return nil, false
	}

	var studentDirs []string
	// Get a list of all the student directories (full path)
	for _, item := range contents {
		if item.IsDir() {
			studentDirs = append(studentDirs, filepath.Join(baseDir, item.Name()))
		}
	}

	studentsLabDirs := make([][]string, len(labs))
	// For each lab
	for i := range studentsLabDirs {
		studentsLabDirs[i] = make([]string, len(studentDirs))

		// For each student
		for j := range studentsLabDirs[i] {
			tempDir := filepath.Join(studentDirs[j], labs[i].Name)
			_, err := ioutil.ReadDir(tempDir)
			if err != nil {
				studentsLabDirs[i][j] = ""
			} else {
				studentsLabDirs[i][j] = tempDir
			}
		}
	}

	return studentsLabDirs, true
}
Esempio n. 9
0
func TestLiveness(t *testing.T) {
	dir := testutil.TempDir()
	defer os.RemoveAll(dir)
	root := nodefs.NewDefaultNode()
	s, _, err := nodefs.MountRoot(dir, root, nil)
	if err != nil {
		t.Fatalf("MountRoot: %v", err)
	}
	go s.Serve()
	if err := s.WaitMount(); err != nil {
		t.Fatal("WaitMount", err)
	}
	defer s.Unmount()

	if _, err := ioutil.ReadDir(dir); err != nil {
		t.Fatalf("ReadDir: %v", err)
	}

	// We previously encountered a sitation where a finalizer would close our fd out from under us. Try to force both finalizers to run and object destruction to complete.
	runtime.GC()
	runtime.GC()

	if _, err := ioutil.ReadDir(dir); err != nil {
		t.Fatalf("ReadDir: %v", err)
	}
}
Esempio n. 10
0
// New is the constructor for a new engine.
func New(root, conditions string) (*Engine, error) {
	hostname, err := os.Hostname()
	if err != nil {
		return nil, err
	}

	engine := &Engine{Root: root, Hostname: hostname}

	if _, err := os.Stat(path.Join(engine.Root, "logic")); err == nil {
		logic, err := ioutil.ReadDir(path.Join(engine.Root, "logic"))
		if err != nil {
			return nil, err
		}
		engine.Logic = logic
	}

	if _, err := os.Stat(path.Join(engine.Root, "stacks")); err == nil {
		stacks, err := ioutil.ReadDir(path.Join(engine.Root, "stacks"))
		if err != nil {
			return nil, err
		}

		engine.Stacks = stacks
	}

	engine.DryRun = true
	engine.PythonPath = "python"
	engine.PipPath = "pip"
	engine.jsVM = otto.New()

	engine.SetConditions(conditions)

	return engine, nil
}
Esempio n. 11
0
func SearchInstance(name string) (instanceName, instancePlatform string) {
	instanceName = ""
	instancePlatform = ""
	rootDir := filepath.Join(HomePath(), ".capstan", "instances")
	platforms, _ := ioutil.ReadDir(rootDir)
	for _, platform := range platforms {
		if !platform.IsDir() {
			continue
		}
		platformDir := filepath.Join(rootDir, platform.Name())
		instances, _ := ioutil.ReadDir(platformDir)
		for _, instance := range instances {
			if !instance.IsDir() {
				continue
			}
			if name != instance.Name() {
				continue
			}
			instanceName = instance.Name()
			instancePlatform = platform.Name()
			return
		}
	}
	return
}
Esempio n. 12
0
func cleanup(directory string) {
	temp, err := ioutil.TempDir("", "")
	isError(err, "")
	files, err := ioutil.ReadDir(directory)
	isError(err, "")
	if 1 == len(files) {
		folder := filepath.Join(directory, files[0].Name())
		// Move to a tmp directory
		files, err = ioutil.ReadDir(folder)
		isError(err, "")
		for _, file := range files {
			var cmd *exec.Cmd
			cmd = exec.Command("mv", file.Name(), temp)
			cmd.Dir = folder
			output, err := cmd.CombinedOutput()
			isError(err, string(output))
		}
		err = os.RemoveAll(folder)
		isError(err, "")
		// move to the directory
		files, err = ioutil.ReadDir(temp)
		isError(err, "")
		for _, file := range files {
			var cmd *exec.Cmd
			cmd = exec.Command("mv", file.Name(), directory)
			cmd.Dir = temp
			output, err := cmd.CombinedOutput()
			isError(err, string(output))
		}
	}
}
Esempio n. 13
0
// list input files
func (in *inputs) listFiles() error {
	list_l1, err := ioutil.ReadDir(in.Directory)
	if err != nil {
		return err
	}
	for _, f_l1 := range list_l1 {
		if f_l1.Mode()&os.ModeSymlink == os.ModeSymlink {
			followed_file, err := os.Readlink(in.Directory + "/" + f_l1.Name())
			if err != nil {
				return err
			}
			if followed_file[0] != '/' {
				followed_file = in.Directory + "/" + followed_file
			}
			f_l1, err = os.Lstat(followed_file)
			if err != nil {
				return err
			}
			logs.WithField("followed_link", f_l1.Name()).Trace("Followed Link")
		}
		if f_l1.IsDir() {
			list_l2, err := ioutil.ReadDir(in.Directory + "/" + f_l1.Name())
			if err != nil {
				return err
			}
			for _, f_l2 := range list_l2 {
				in.Files = append(in.Files, f_l1.Name()+"/"+f_l2.Name())
			}
		} else {
			in.Files = append(in.Files, f_l1.Name())
		}
	}
	return nil
}
Esempio n. 14
0
func getFolders(path string) (map[string][]string, error) {
	folders := make(map[string][]string)
	codecFileInfos, err := ioutil.ReadDir(path)
	if err != nil {
		return nil, err
	}
	for _, codecFileInfo := range codecFileInfos {
		if !codecFileInfo.IsDir() {
			continue
		}
		codecFolderName := codecFileInfo.Name()
		codecPath := filepath.Join(path, codecFolderName)
		caseDirInfos, err := ioutil.ReadDir(codecPath)
		if err != nil {
			return nil, err
		}
		for _, caseDirInfo := range caseDirInfos {
			if !caseDirInfo.IsDir() {
				continue
			}
			casePath := filepath.Join(codecPath, caseDirInfo.Name())
			folders[codecFolderName] = append(folders[codecFolderName], casePath)
		}
	}
	return folders, nil
}
func getLogList() ([]string, error) {
	var (
		files []string
		err   error
	)
	fileData, err := ioutil.ReadDir("dalek/logs")
	for _, f := range fileData {
		if f.IsDir() {
			console, manifest := false, false
			fileData, err := ioutil.ReadDir("dalek/logs/" + f.Name())
			if err != nil {
				return files, err
			}
			for _, f := range fileData {
				if f.Name() == "manifest.json" {
					manifest = true
				} else if f.Name() == "console.log" {
					console = true
				}
			}
			if manifest && console {
				files = append(files, f.Name())
			}
		}
	}
	return files, err
}
Esempio n. 16
0
func getFileList() RecordedFileList {
	rootPath := *record + "record" + string(os.PathSeparator)

	// Read all the directory in the record folder
	files, _ := ioutil.ReadDir(rootPath)

	var recordedFiles RecordedFileList
	var fileList []RecordedFileInfo

	for _, f := range files {
		if f.IsDir() { // Find subfolders
			subFiles, _ := ioutil.ReadDir(rootPath + string(os.PathSeparator) + f.Name()) // Get the subfiles within subfolder
			for _, sf := range subFiles {
				subFile := new(RecordedFileInfo)         // Create struct
				subFile.RcrdFolder = rootPath + f.Name() // Set folder
				subFile.RcrdFile = sf.Name()             // Set file name
				fileList = append(fileList, *subFile)    // Add struct to list
			}
		}
	}

	// Set the file list
	recordedFiles.FileList = fileList

	fmt.Println("Recorded Files: ", recordedFiles)

	return recordedFiles
}
Esempio n. 17
0
func (this *launcher_commands) LolSetConfigPath(gameroot_path, runtime_path string) error {
	_, e := ioutil.ReadDir(gameroot_path)
	if e != nil {
		return e
	}
	this.gameroot_path = gameroot_path

	_, e = ioutil.ReadDir(runtime_path)
	if e != nil {
		return e
	}
	this.runtime_path = runtime_path

	this.gamelog_path = this.runtime_path + "/logs/"
	if _, e = os.Stat(this.gamelog_path); e != nil {
		e = os.Mkdir(this.gamelog_path, 0777)
		if e != nil {
			return e
		}
	}

	this.client_cn_dirname = "lol_air_client" //默认英文客户端路径
	//	this.client_cn_dirname = "lol_air_client_tencent"	//中文客户端路径
	return nil
}
Esempio n. 18
0
func TestDiskPublisherWrite(t *testing.T) {
	o := oops.Oops{
		Id:    "oopsId",
		Error: errors.New("this is an error").Error(),
	}
	tempFolder, err := ioutil.TempDir("/tmp", "oops")
	if err != nil {
		t.Error("error creating temporary directory for oopses")
	}
	defer os.RemoveAll(tempFolder)

	fileInfo, err := ioutil.ReadDir(tempFolder)
	if err != nil {
		t.Error("error reading temporary directory")
	}
	if len(fileInfo) != 0 {
		t.Error("error, temporary directory not empty")
	}
	dp := oops.DiskPublisher{tempFolder}
	err = dp.Write(o)
	if err != nil {
		t.Error("error writing the oops")
	}
	fileInfo, err = ioutil.ReadDir(tempFolder)
	if err != nil {
		t.Error("error reading temporary directory")
	}
	if len(fileInfo) != 1 {
		t.Error("error, temporary directory should contain only one oops")
	}
}
Esempio n. 19
0
// using the servicebuilder yaml files, find any extraneous runit services and
// remove them
// runsvdir automatically stops services that no longer exist, explicit stop is
// not required
func (s *ServiceBuilder) Prune() error {
	configs, err := s.loadConfigDir()
	if err != nil {
		return err
	}

	links, err := ioutil.ReadDir(s.RunitRoot)
	if err != nil {
		return err
	}
	for _, link := range links {
		if _, exists := configs[link.Name()]; !exists {
			if err = os.Remove(filepath.Join(s.RunitRoot, link.Name())); err != nil {
				return err
			}
		}
	}

	stages, err := ioutil.ReadDir(s.StagingRoot)
	if err != nil {
		return err
	}
	for _, stage := range stages {
		if _, exists := configs[stage.Name()]; !exists {
			if err = os.RemoveAll(filepath.Join(s.StagingRoot, stage.Name())); err != nil {
				return err
			}
		}
	}

	return nil
}
Esempio n. 20
0
// Takes the path to the addons directory and returns a slice of addons
func getAddons(addonsDirectory string) []addon {
	addons := make([]addon, 0)
	addonDirectories, _ := ioutil.ReadDir(addonsDirectory)
	for _, addonDirectory := range addonDirectories {
		filesInAddonDirectory, err := ioutil.ReadDir(addonsDirectory + "/" + addonDirectory.Name() + "/")
		if err != nil {
			log.Fatal(err)
		}
		for _, addonFile := range filesInAddonDirectory {
			if strings.HasSuffix(addonFile.Name(), ".toc") {
				tocFile, err := ioutil.ReadFile(addonsDirectory + "/" + addonDirectory.Name() + "/" + addonFile.Name())
				if err != nil {
					log.Fatal(err)
				}
				id, version := getAddonProperties(addonDirectory.Name(), string(tocFile))
				if version == "" {
					addon := addon{id: id, successful: false}
					if id != "" && !contains(addons, addon) {
						addons = append(addons, addon)
					}
				} else {
					addon := addon{id: id, version: version, successful: true}
					if id != "" && !contains(addons, addon) {
						addons = append(addons, addon)
					}
				}

			}
		}
	}
	return addons
}
Esempio n. 21
0
func compareDir(actualDir, expectedDir string) {
	actualDirInfo, err := os.Stat(actualDir)
	Expect(err).NotTo(HaveOccurred())

	expectedDirInfo, err := os.Stat(expectedDir)
	Expect(err).NotTo(HaveOccurred())

	Expect(actualDirInfo.Mode()).To(Equal(expectedDirInfo.Mode()))

	actualFiles, err := ioutil.ReadDir(actualDir)
	Expect(err).NotTo(HaveOccurred())

	expectedFiles, err := ioutil.ReadDir(actualDir)
	Expect(err).NotTo(HaveOccurred())

	Expect(len(actualFiles)).To(Equal(len(expectedFiles)))
	for i, actualFile := range actualFiles {
		expectedFile := expectedFiles[i]
		if actualFile.IsDir() {
			compareDir(filepath.Join(actualDir, actualFile.Name()), filepath.Join(expectedDir, expectedFile.Name()))
		} else {
			compareFile(filepath.Join(actualDir, actualFile.Name()), filepath.Join(expectedDir, expectedFile.Name()))
		}
	}
}
Esempio n. 22
0
func ReadHexDatabase(d string) map[string]bool {
	hexRe := regexp.MustCompile("^([0-9a-fA-F][0-9a-fA-F])+$")
	db := map[string]bool{}
	entries, err := ioutil.ReadDir(d)
	if err != nil {
		return db
	}

	for _, e := range entries {
		if !hexRe.MatchString(e.Name()) || !e.IsDir() {
			continue
		}

		sub, _ := ioutil.ReadDir(fastpath.Join(d, e.Name()))
		for _, s := range sub {
			if !hexRe.MatchString(s.Name()) || s.IsDir() {
				continue
			}

			hex := e.Name() + s.Name()
			bin := make([]byte, len(hex)/2)
			n, err := fmt.Sscanf(hex, "%x", &bin)
			if n != 1 {
				log.Panic("sscanf %d %v", n, err)
			}

			db[string(bin)] = true
		}
	}

	return db
}
Esempio n. 23
0
func TestFlatstoreitProcessFiles(t *testing.T) {
	if err := ioutil.WriteFile(path.Join("/tmp", "acc_1.log"), []byte(fullSuccessfull), 0644); err != nil {
		t.Fatal(err.Error)
	}
	if err := ioutil.WriteFile(path.Join("/tmp", "missed_calls_1.log"), []byte(fullMissed), 0644); err != nil {
		t.Fatal(err.Error)
	}
	if err := ioutil.WriteFile(path.Join("/tmp", "acc_2.log"), []byte(part1), 0644); err != nil {
		t.Fatal(err.Error)
	}
	if err := ioutil.WriteFile(path.Join("/tmp", "acc_3.log"), []byte(part2), 0644); err != nil {
		t.Fatal(err.Error)
	}
	//Rename(oldpath, newpath string)
	for _, fileName := range []string{"acc_1.log", "missed_calls_1.log", "acc_2.log", "acc_3.log"} {
		if err := os.Rename(path.Join("/tmp", fileName), path.Join(flatstoreCdrcCfg.CdrInDir, fileName)); err != nil {
			t.Fatal(err)
		}
	}
	time.Sleep(time.Duration(3) * time.Second) // Give time for processing to happen and the .unparired file to be written
	filesInDir, _ := ioutil.ReadDir(flatstoreCdrcCfg.CdrInDir)
	if len(filesInDir) != 0 {
		t.Errorf("Files in cdrcInDir: %+v", filesInDir)
	}
	filesOutDir, _ := ioutil.ReadDir(flatstoreCdrcCfg.CdrOutDir)
	if len(filesOutDir) != 5 {
		t.Errorf("In CdrcOutDir, expecting 5 files, got: %d", len(filesOutDir))
	}
	ePartContent := "INVITE|2daec40c|548625ac|dd0c4c617a9919d29a6175cdff223a9e@0:0:0:0:0:0:0:0|200|OK|1436454408|*prepaid|1001|1002||3401:2069362475\n"
	if partContent, err := ioutil.ReadFile(path.Join(flatstoreCdrcCfg.CdrOutDir, "acc_3.log.unpaired")); err != nil {
		t.Error(err)
	} else if ePartContent != string(partContent) {
		t.Errorf("Expecting: %s, received: %s", ePartContent, string(partContent))
	}
}
Esempio n. 24
0
func runAllTests() []result {
	invalidTests, err := ioutil.ReadDir(dirInvalid)
	if err != nil {
		log.Fatalf("Cannot read invalid directory (%s): %s", dirInvalid, err)
	}

	validTests, err := ioutil.ReadDir(dirValid)
	if err != nil {
		log.Fatalf("Cannot read valid directory (%s): %s", dirValid, err)
	}

	results := make([]result, 0, len(invalidTests)+len(validTests))
	for _, f := range invalidTests {
		if !strings.HasSuffix(f.Name(), fmt.Sprintf(".%s", invalidExt)) {
			continue
		}
		tname := stripSuffix(f.Name())
		results = append(results, runInvalidTest(tname))
	}
	for _, f := range validTests {
		if !strings.HasSuffix(f.Name(), ".toml") {
			continue
		}
		tname := stripSuffix(f.Name())
		results = append(results, runValidTest(tname))
	}
	return results
}
Esempio n. 25
0
File: hist.go Progetto: 0x7cc/rsc
func loadDates() []string {
	var all []string
	ydir, err := ioutil.ReadDir(filepath.Join(*mtpt, *host))
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(3)
	}
	for _, y := range ydir {
		if !y.IsDir() || !yyyy.MatchString(y.Name()) {
			continue
		}
		ddir, err := ioutil.ReadDir(filepath.Join(*mtpt, *host, y.Name()))
		if err != nil {
			continue
		}
		for _, d := range ddir {
			if !d.IsDir() || !mmdd.MatchString(d.Name()) {
				continue
			}
			date := y.Name() + "/" + d.Name()
			if *vers > date {
				continue
			}
			all = append(all, filepath.Join(*mtpt, *host, date))
		}
	}
	return all
}
Esempio n. 26
0
func checkFileNamesAndMigrate(depDir, newDir string) error {
	depDirFiles, err := ioutil.ReadDir(depDir)
	if err != nil {
		return fmt.Errorf("could not read files from dir to be deprecated %s:\n%v\n", depDir, err)
	}
	newDirFiles, err := ioutil.ReadDir(newDir)
	if err != nil {
		return fmt.Errorf("could not read files from new dir %s:\n%v\n", newDir, err)
	}

	fileNamesToCheck := make(map[string]bool) //map of filenames in new dir
	if len(newDirFiles) != 0 {
		for _, file := range newDirFiles {
			fileNamesToCheck[file.Name()] = true
		}
	}

	for _, file := range depDirFiles { //if any filenames match, must resolve
		depFile := path.Join(depDir, file.Name())
		newFile := path.Join(newDir, file.Name()) //file may not actually exist (yet)

		if fileNamesToCheck[file.Name()] == true { //conflict!
			return fmt.Errorf("identical file name in deprecated dir (%s) and new dir to migrate to (%s)\nplease resolve and re-run command", depFile, newFile)
		} else { //filenames don't match, move file from depDir to newDir

			if err := os.Rename(depFile, newFile); err != nil {
				logger.Errorf("File migration NOT succesful:\t%s ====> %s\n", depFile, newFile)
				return err
			}
			logger.Printf("File migration succesful:\t%s ====> %s\n", depFile, newFile)
		}
	}
	return nil
}
Esempio n. 27
0
func getPicData(pic_path string) (pic_datas []PicData) {

	pic_datas = make([]PicData, 0, 10)
	pic_data := new(PicData)

	dir, err := ioutil.ReadDir(pic_path)

	if err != nil {
		println("ReadDir faild")
		return
	}
	i := 0
	for _, v := range dir {
		if i >= 100 {
			break
		}
		if v.IsDir() {
			i++
			pic_data.pics = make([]string, 0, 10)
			pic_data.name = v.Name()

			subdir, _ := ioutil.ReadDir(pic_path + "/" + v.Name())
			for _, f := range subdir {
				// println(f.Name())
				pic_data.pics = append(pic_data.pics, f.Name())
			}

			pic_datas = append(pic_datas, *pic_data)
		}
	}
	return

}
Esempio n. 28
0
func (r *Repo) ListImages() {
	fmt.Println(FileInfoHeader())
	namespaces, _ := ioutil.ReadDir(r.Path)
	for _, n := range namespaces {
		images, _ := ioutil.ReadDir(filepath.Join(r.Path, n.Name()))
		nrImages := 0
		nrFiles := 0
		for _, i := range images {
			if i.IsDir() {
				info := MakeFileInfo(r.Path, n.Name(), i.Name())
				if info == nil {
					fmt.Println(n.Name() + "/" + i.Name())
				} else {
					fmt.Println(info.String())
				}
				nrImages++
			} else {
				nrFiles++
			}
		}
		// Image is directly at repository root with no namespace:
		if nrImages == 0 && nrFiles != 0 {
			fmt.Println(n.Name())
		}
	}
}
Esempio n. 29
0
func TemplateInit() {
	var allFiles []string
	files, err := ioutil.ReadDir("./web/frontend_templates")
	if err != nil {
		fmt.Println(err)
	}
	files2, err := ioutil.ReadDir("./web/frontend_templates/partials")
	if err != nil {
		fmt.Println(err)
	}

	for _, file := range files {
		filename := file.Name()
		log.Println(filename)
		if strings.HasSuffix(filename, ".html") {
			allFiles = append(allFiles, "./web/frontend_templates/"+filename)
		}
	}

	for _, file := range files2 {
		filename := file.Name()
		log.Println(filename)
		if strings.HasSuffix(filename, ".html") {
			allFiles = append(allFiles, "./web/frontend_templates/partials/"+filename)
		}
	}

	templates = template.Must(template.ParseFiles(allFiles...))
}
Esempio n. 30
0
File: list.go Progetto: nariyu/gigo
//List provides list of packages in $GOPATH/src
func List(c *cli.Context) {

	srcpath := fmt.Sprintf("%s/src/", os.Getenv("GOPATH"))
	srcdir, err := ioutil.ReadDir(srcpath)
	if err != nil {
		log.Fatal(err)
	}
	if len(srcdir) == 0 {
		log.Fatal(fmt.Sprintf("%s is empty", srcpath))
	}
	for _, source := range srcdir {
		fmt.Println("Packages from " + source.Name())
		title, err := ioutil.ReadDir(srcpath + source.Name())
		if err != nil {
			log.Print(err)
		}

		for _, pack := range title {
			if pack.IsDir() {
				fmt.Println(pack.Name())
			}
		}
		fmt.Println("\n")
	}
}