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

stream: don't try to read from all-sparse/no-data files #13817

Merged
merged 1 commit into from May 7, 2024

Conversation

MoSal
Copy link
Contributor

@MoSal MoSal commented Apr 4, 2024

dd if=/dev/zero of=/tmp/10g.empty bs=1 seek=10G count=0
dd if=/dev/zero of=/tmp/10m.empty bs=1 seek=10M count=0
time mpv /tmp/10{g,m}.empty

I keep files with the name format ${name}-${hash}.${ext}.empty around, where the original is removed, and a sparse file with the size of the original is created instead.

A lot of time is wasted on such files when going through playlists/directories that include some of them.

This admittedly may not be that common of a use-case.

Copy link

github-actions bot commented Apr 4, 2024

Download the artifacts for this pull request:

Windows
macOS

@MoSal
Copy link
Contributor Author

MoSal commented Apr 4, 2024

Checks reveal support for SEEK_DATA is on for Linux, mac, and FreeBSD. And off for Windows and OpenBSD, as expected.

There is one exception. The check fails in linux-ffmpeg-4-4.

@na-na-hi
Copy link
Contributor

na-na-hi commented Apr 4, 2024

There is one exception. The check fails in linux-ffmpeg-4-4.

SEEK_DATA was added for musl 1.2.3. Alpine Linux 3.15 (used for linux-ffmpeg-4-4) ships musl 1.2.2.

@MoSal
Copy link
Contributor Author

MoSal commented Apr 4, 2024

There is one exception. The check fails in linux-ffmpeg-4-4.

SEEK_DATA was added for musl 1.2.3. Alpine Linux 3.15 (used for linux-ffmpeg-4-4) ships musl 1.2.2.

Cool. Thanks for the info.

@sfan5
Copy link
Member

sfan5 commented Apr 5, 2024

The use case is strange but I can't think of any downsides of rejecting empty files early like this, so should be fine.

meson.build Outdated Show resolved Hide resolved
stream/stream_file.c Show resolved Hide resolved
stream/stream_file.c Outdated Show resolved Hide resolved
stream/stream_file.c Outdated Show resolved Hide resolved
@MoSal
Copy link
Contributor Author

MoSal commented Apr 6, 2024

Review addressed.

meson.build Outdated Show resolved Hide resolved
 ```
 dd if=/dev/zero of=/tmp/10g.empty bs=1 seek=10G count=0
 dd if=/dev/zero of=/tmp/10m.empty bs=1 seek=10M count=0
 time mpv /tmp/10{g,m}.empty
 ```

 I keep files with the name format `${name}-${hash}.${ext}.empty`
 around, where the original is removed, and a sparse file with
 the size of the original is created instead.

 A lot of time is wasted on such files when going through
 playlists/directories that include some of them.

 This admittedly may not be that common of a use-case.

Signed-off-by: Mohammad AlSaleh <[email protected]>
@kasper93 kasper93 merged commit bb7a485 into mpv-player:master May 7, 2024
17 checks passed
@cheemeng
Copy link

@MoSal On MacOS Sonoma, this commit removes the ability to drag and drop a folder unto the mpv player.
image

@MoSal
Copy link
Contributor Author

MoSal commented May 12, 2024

@cheemeng

Interesting. The seek doesn't fail with directories in GNU/Linux, even if they are empty.

Can you confirm this change fixes the issue?

 stream/stream_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stream/stream_file.c b/stream/stream_file.c
index 0a6a697ff6..4b23d7fb83 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -359,7 +359,7 @@ static int open_f(stream_t *stream, const struct stream_open_args *args)
 #endif
 
 #if HAVE_SEEK_DATA
-    if (stream->mode == STREAM_READ) {
+    if (stream->mode == STREAM_READ && !stream->is_directory) {
         off_t first_data = lseek(p->fd, 0, SEEK_DATA);
         if (first_data == (off_t)-1 && errno == ENXIO) {
             MP_ERR(stream, "File is empty or all sparse (has no data).\n");

@sfan5
Copy link
Member

sfan5 commented May 12, 2024

@kasper93 and I discussed on IRC that we will likely be reverting this anyway because it also introduces an error message if you pass an empty file to e.g. --input-conf, which is nonsense.
The stream layer is just the wrong place to make this change.

@cheemeng
Copy link

cheemeng commented May 12, 2024

Yup @MoSal , that would skip the throwing of errors when it's a directory, dragging in a folder works fine now.

PS: Perhaps this option to skip sparse files can also be added as one of the mpv list of 'features' in meson_options.txt so it can be disabled during compilation itself as well?

@MoSal
Copy link
Contributor Author

MoSal commented May 12, 2024

@cheemeng
See comment above you in case you missed it.
Looks like this will be reverted altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants