Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I try to get all the files in the directory, the list of files I get is empty #405

Open
Aliuyanfeng opened this issue Nov 15, 2024 · 0 comments
Labels
defect The code does not work as intended

Comments

@Aliuyanfeng
Copy link

Aliuyanfeng commented Nov 15, 2024

Describe the bug
I use the Walk method to get the file traversal, but can not get the file in the directory, but there are files in the directory

To Reproduce

	file, err := os.Open(indexTableName)
	if err != nil {
		log.Println(fmt.Sprintf("open file failed, %s;", err))
	}
	oldFileAbsPath := make(map[string]struct{})
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := scanner.Text()
		oldFileAbsPath[line] = struct{}{}
	}
	_ = file.Close()

	err = conn.Conn.ChangeDir(remoteFolderPath)
	if err != nil {
		oldFileAbsPath = nil
		return nil, errors.New(fmt.Sprintf("path failed:%s,:%s", remoteFolderPath, err))
	}

	fileAbsPath := make(map[string]string)
	pathsSplit := strings.Split(remoteFolderPath, "/")
	walker := conn.Conn.Walk(remoteFolderPath)
	var builder strings.Builder
	for walker.Next() {
		info := walker.Stat()
		if info.Type.String() == "folder" {
			continue
		}
		if info == nil {
			continue
		}
		v := walker.Path()

		vSplit := strings.Split(path.Dir(v), "/")
	
		if len(vSplit)-1 > (len(pathsSplit)-1+folderLevel) && folderLevel > 0 && folderLevel != 0 {
			continue
		}

		builder.WriteString(v)
		builder.WriteRune('-')
		builder.WriteString(strconv.FormatUint(info.Size, 10))
		builder.WriteRune('-')
		builder.WriteString(info.Time.Format("20060102150405"))
		m5 := builder.String()
		//m5 := v + "-" + strconv.FormatUint(info.Size, 10) + "-" + info.Time.Format("20060102150405")
		if _, ok := oldFileAbsPath[m5]; !ok {
		
			fileAbsPath[v] = m5
		}
		builder.Reset()

	}
	if err = walker.Err(); err != nil {
		log.Println(fmt.Sprintf("path failed:%s,:%s", remoteFolderPath, err))
	}
	oldFileAbsPath = nil

FTP server

  • Name and version: vsftpd 3.0.2

Additional context
Is it related to the file system string?

Looking forward to reply! 🤣

@Aliuyanfeng Aliuyanfeng added the defect The code does not work as intended label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect The code does not work as intended
Projects
None yet
Development

No branches or pull requests

1 participant