Пример #1
0
func Take(files []string) {
	chestPath := utils.GetChestPath()
	rootPath := filepath.Dir(chestPath)

	if !utils.ExistsFile(chestPath) {
		fmt.Println("Chest not found")
		return
	}

	for _, file := range files {
		chestInFilePath := filepath.Join(chestPath, file)
		if !utils.ExistsFile(chestInFilePath) {
			fmt.Println("File not found: " + chestInFilePath)
			return
		}

		rootInFilePath := filepath.Join(rootPath, file)
		if utils.ExistsFile(rootInFilePath) {
			fmt.Println("File already exist in root: " + rootInFilePath)
			fmt.Println("diff:")
			utils.PrintFileDiff(chestInFilePath, rootInFilePath)
			return
		}

		os.Remove(rootInFilePath)
		os.Rename(chestInFilePath, rootInFilePath)
	}
}
Пример #2
0
func Close() {
	chestPath := utils.GetChestPath()

	if !utils.ExistsFile(chestPath) {
		fmt.Println("Chest not found")
		return
	}

	files, err := ioutil.ReadDir(chestPath)
	if err != nil {
		panic(err)
	}

	if len(files) == 0 {
		fmt.Println("Chest is blank")
		return
	}

	rootPath := filepath.Dir(chestPath)
	for _, file := range files {
		filePath := filepath.Join(rootPath, file.Name())
		if !utils.ExistsFile(filePath) {
			return
		}

		if err := os.Remove(filePath); err != nil {
			panic(err)
		}
	}
}
Пример #3
0
func Open() {
	chestPath := utils.GetChestPath()

	if !utils.ExistsFile(chestPath) {
		fmt.Println("Chest not found")
		return
	}

	files, err := ioutil.ReadDir(chestPath)
	if err != nil {
		panic(err)
	}

	if len(files) == 0 {
		fmt.Println("Chest is blank")
		return
	}

	rootPath := filepath.Dir(chestPath)
	for _, file := range files {
		fileName := file.Name()
		filePath := filepath.Join(rootPath, fileName)
		if utils.ExistsFile(filePath) {
			fmt.Println("File already exist: " + fileName)
			return
		}

		if err := os.Symlink(filepath.Join(chestPath, fileName), filePath); err != nil {
			panic(err)
		}
	}
}
Пример #4
0
func List() {
	chestPath := utils.GetChestPath()

	if !utils.ExistsFile(chestPath) {
		fmt.Println("Chest not found")
		return
	}

	files, err := ioutil.ReadDir(chestPath)
	if err != nil {
		panic(err)
	}

	if len(files) == 0 {
		fmt.Println("Chest is blank")
		return
	}

	for _, file := range files {
		fmt.Println(file.Name())
	}
}