From 06dd45bfd5e758cedd716d2514bf92c3f738b752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 30 Jun 2021 23:22:09 +0200 Subject: [PATCH] Do special case ENOENT after all Otherwise seeking into a raw dmg file will fail when hitting parts of it that are not covered by a band. The expectation in that case is to pad with zeroes, like we do for partial bands. --- src/sparsebundlefs.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sparsebundlefs.cpp b/src/sparsebundlefs.cpp index 4b6f7c2..c3a3f14 100644 --- a/src/sparsebundlefs.cpp +++ b/src/sparsebundlefs.cpp @@ -229,9 +229,13 @@ static int sparsebundle_open_file(const char *path) sparsebundle_close_files(); return sparsebundle_open_file(path); + } else if (errno == ENOENT) { + syslog(LOG_DEBUG, "%s does not exist", path); + return -1; + } else { + syslog(LOG_ERR, "failed to open %s: %s", path, strerror(errno)); + return -1; } - syslog(LOG_ERR, "failed to open %s: %s", path, strerror(errno)); - return -1; } sparsebundle->open_files[path] = fd; @@ -319,7 +323,7 @@ static int sparsebundle_read_process_band(const char *band_path, size_t length, int band_file_fd = sparsebundle_open_file(band_path); if (band_file_fd == -1) - return -errno; + return errno == ENOENT ? 0 : -errno; read = pread(band_file_fd, *buffer, length, offset); if (read == -1) { @@ -371,7 +375,7 @@ static int sparsebundle_read_buf_process_band(const char *band_path, size_t leng int band_file_fd = sparsebundle_open_file(band_path); if (band_file_fd == -1) - return -errno; + return errno == ENOENT ? 0 : -errno; struct stat band_stat; stat(band_path, &band_stat);