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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]: View all included files #6108
Conversation
@@ -71,9 +112,75 @@ func (s *FolderStatisticsReference) GetLastScanTime() time.Time { | |||
return lastScan | |||
} | |||
|
|||
func listFiles(dir string) []string { | |||
var res []string | |||
filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of filepath.Walk
is not checked (from errcheck
)
result.Children = append(result.Children, child) | ||
} | ||
} else { | ||
var child FolderTreeStructure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S1021: should merge variable declaration with assignment on next line (from gosimple
)
So I think the UI part (tree view etc) is the harder part of this ticket. Implementing the logic itself to return files should not be too hard. I can see this PR uses FolderStats stuff, but that's meant for completely different purpose, which is persistence of metrics |
That means to create new route in the api, right?
Do you also mean every subdirectory in our syncing directory?
I am sorry, I didn't know. I read the whole documentation (hope carefully enough), but didn't notice anything about FolderStats purpose. |
I think there already exists an endpoint for what you are trying to do. We'd probably make a request for every subdirectory, as people can have millions of files, and returning everything in a simple response might be too expensive. |
You are right. I assumed |
We might need to modify that endpoint, as I think what it returns is really bad (maps of stuff). I don't think anyone uses that. so it should be ok. It should return:
so it's array based, rather than map based. |
This function iterates over every file or folder in the given part of the file system and calls fn(f) on its path (which is of type string).: That means, that the anonymous function defined in Then we check every folder on a particular path (e.g for path '/folder1/file1' we split it and check Also, converting the output structure before returning it to an array-based structure seems rather unprofessional to me. Is it really necessary to change the output's type? I understand it would look nicer with arrays, but as far as I understand the code, I don't see more efficient solution than convert the output structure before returning it. :/ Do you have a different opinion? |
I don't think you need to modify withGlobal. WithGlobal iterates in a sorted fashion, so /folder/ will always be before /folder/file. You simply need to have a stack of directories as you traverse in and out of them, and your children will always be in the top directory of the stack. |
Purpose
Hi, I would like to contribute to Syncthing. 馃槂
I found an enhancement issue #4729. I suppose no one is working on it because it is inactive since 2018. I tried to implement it.
Testing
I suppose, It would be nice to display not only some plain list of files (as I implemented firstly)
but some nice folder tree structure.
What do you think?
I think a nested folder structure in JSON format would be useful when displaying the folder tree view in Angularjs. I wrote a function in Go which converts a list of files (and trims the paths from the Sync base folder path) into such a nested structure. I wrote tests to test it as well. Tests are in
lib/stats/folder_test.go
.But the (frontend) Angularjs part is not ready, yet.
I already started to implement this, but got stuck on creating a new directive in angular. I've never written anything in Anlgularjs, therefore I need to read the documentation first.
Are you okay if I finish this PR? What do you think about the file tree view?
Screenshots
I added a new item in folder statistics view. (Of course, I also add translations later.)
After clicking on
show
, a popup appears and should show a nice tree structure.For now, I send a file tree structure in JSON format.
I hope you can bear with me one or two PRs. 馃槂
Authorship
Your name and email will be added automatically to the AUTHORS file
based on the commit metadata.