// GetAll : All file paths printer
func GetAll(w http.ResponseWriter, r *http.Request) {

	currDir := "/"

	var conn, _ = redisurl.ConnectToURL(redisURL)

	files, _ := redis.Strings(conn.Do("KEYS", "*"))
	baseDirEndIndex := len(currDir)
	dirArr := []string{}
	fileArr := []string{}

	for _, file := range files {
		if strings.Index(file, currDir) == 0 {
			relpath := file[baseDirEndIndex:]
			fileordir := strings.Index(relpath, "/")

			if fileordir == -1 {

				fileArr = append(fileArr, relpath)

			} else {

				path := relpath[:fileordir+1]

				if !util.SliceContains(dirArr, path) {
					dirArr = append(dirArr, path)
				}

			}

		}
	}

	// Print the dirs found
	for _, dirname := range dirArr {

		fmt.Fprintf(w, "dir \t--\t %s\n", dirname)
	}

	//Print the files found
	for _, filename := range fileArr {

		fmt.Fprintf(w, "file \t--\t %s\n", filename)
	}

	conn.Close()

}
Beispiel #2
0
// LSHandler : Handler for the LS command
func LSHandler(conn redis.Conn, currDir string) {

	files, _ := redis.Strings(conn.Do("KEYS", "*"))
	baseDirEndIndex := len(currDir)
	dirArr := []string{}
	fileArr := []string{}

	for _, file := range files {
		if strings.Index(file, currDir) == 0 {
			relpath := file[baseDirEndIndex:]
			fileordir := strings.Index(relpath, "/")

			if fileordir == -1 {

				fileArr = append(fileArr, relpath)

			} else {

				path := relpath[:fileordir+1]

				if !util.SliceContains(dirArr, path) {
					dirArr = append(dirArr, path)
				}

			}

		}
	}

	// Print the dirs found
	for _, dirname := range dirArr {

		fmt.Printf("dir \t--\t %s\n", "/"+dirname)
	}

	//Print the files found
	for _, filename := range fileArr {

		fmt.Printf("file \t--\t %s\n", "/"+filename)
	}

}