Skip to content

file: implement support for directory listing - #9746

Closed
cvengler wants to merge 2 commits into
curl:masterfrom
cvengler:2022-10-directory-listing
Closed

cvengler wants to merge 2 commits into
curl:masterfrom
cvengler:2022-10-directory-listing

Conversation

@cvengler

@cvengler cvengler commented Oct 16, 2022 •

Copy link
Copy Markdown

Based on #9745

This commit implements support to the file:// protocol for directory
listings, similar to FTP.

Directory entries are printed as follows:
MODE SIZE MTIME NAME

An example directory listing:

[engler@lennon curl]$ src/curl file:///home/engler
drwxr-xr-x	0	Oct 12 14:09	Desktop
drwxr-xr-x	362	Oct 14 08:31	Downloads
drwxr-xr-x	0	Oct 12 14:09	Templates
drwxr-xr-x	0	Oct 12 14:09	Public
drwxr-xr-x	0	Oct 12 14:09	Documents
drwxr-xr-x	0	Oct 12 14:09	Music
drwxr-xr-x	108	Oct 14 08:34	Pictures
drwxr-xr-x	0	Oct 12 14:09	Videos
drwxr-xr-x	96	Oct 15 17:58	projects
-rw-r--r--	2278067	Oct 13 18:51	wallpaper.jpg
drwxr-xr-x	12	Oct 14 11:21	go

@bagder bagder added the feature-window A merge of this requires an open feature window label Oct 17, 2022
Comment thread lib/file.c Resolved
@vszakats

vszakats commented Oct 17, 2022 •

Copy link
Copy Markdown
Member

curl FTP file listing works such that it requires an ending slash to trigger it. This ensures that the result is either a file listing or an error (vs. either, depending on the state of the filesystem). It'd be useful to replicate that here as well IMO.

@cvengler

Copy link
Copy Markdown
Author

curl FTP file listing works such that it requires an ending slash to trigger it. This ensures that the result is either a file listing or an error (vs. either, depending on the state of the filesystem). It'd be useful to replicate that here as well IMO.

This is a good suggestion. I'll fix that.

@gvanem

gvanem commented Oct 17, 2022

Copy link
Copy Markdown
Contributor

What about the targets (like MSVC) that does not have <dirent.h> ?

@cvengler

Copy link
Copy Markdown
Author

What about the targets (like MSVC) that does not have <dirent.h> ?

Nothing will happen in these cases. There are preprocessor conditions that check for the existence of fdopendir and <dirent.h>. However, I am unsure if the current way of ignoring is good practice. Maybe fetch_file should be called in that case, just like it happened earlier?

@cvengler

Copy link
Copy Markdown
Author

Interesting, opendir(3) works in an unstable way in terms of sorting. Guess I need to implement some sort of sorting.

@cvengler
cvengler force-pushed the 2022-10-directory-listing branch 3 times, most recently from 9a88ef9 to ba65d85 Compare October 20, 2022 11:15
@bagder

bagder commented Nov 5, 2022

Copy link
Copy Markdown
Member

The fuzzer found problems. This now has merge conflicts.

@cvengler
cvengler force-pushed the 2022-10-directory-listing branch 3 times, most recently from 01e34d6 to dc14d2c Compare November 11, 2022 16:14
@bagder

bagder commented Nov 28, 2022

Copy link
Copy Markdown
Member

This PR has conflicts and still has test failures.

@dfandrich

Copy link
Copy Markdown
Contributor

Does this patch support --list-only as well? That would simplify one use case I have.

@cvengler

cvengler commented Dec 7, 2022

Copy link
Copy Markdown
Author

I haven't forgot the PR yet, but I'm currently very busy. It may take until christmas holidays, until I find some free time again :/

@cvengler
cvengler force-pushed the 2022-10-directory-listing branch from dc14d2c to af18bb2 Compare December 11, 2022 08:56
@cvengler

Copy link
Copy Markdown
Author

Rebased to 99f72c0

@cvengler
cvengler force-pushed the 2022-10-directory-listing branch from af18bb2 to 3727825 Compare December 11, 2022 08:58
@cvengler

Copy link
Copy Markdown
Author

Does this patch support --list-only as well? That would simplify one use case I have.

Not yet, but it seems like a good suggestion. I will first try to investigate the CI and fuzzer fails though.

@cvengler
cvengler force-pushed the 2022-10-directory-listing branch 2 times, most recently from 6b84faf to 0879a07 Compare December 11, 2022 20:30
This commit refactors the file_do() function, by placing much of the
logic into a separate function called fetch_file(), which in turn
contains a partially refactored version of the previous code found for
fetching files.

The driving force behind that commit is the possibility to add a later
feature for a directory listing, such as the one found in FTP.
@cvengler
cvengler force-pushed the 2022-10-directory-listing branch 4 times, most recently from b8e9db7 to 6e84a21 Compare December 14, 2022 07:08
@cvengler
cvengler force-pushed the 2022-10-directory-listing branch 3 times, most recently from d12500b to 5e7f645 Compare December 20, 2022 09:52
This commit implements support to the file:// protocol for directory
listings, similar to FTP.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-window A merge of this requires an open feature window needs-info

Development

Successfully merging this pull request may close these issues.

5 participants