~lanodan/public-inbox

deblob: io::close can error v1 APPLIED

Sebastian: 3
 io::close can error
 Replace fmt::fatal with fmt::fatalf
 Simplify is_blob

 3 files changed, 6 insertions(+), 9 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~lanodan/public-inbox/patches/32019/mbox | git am -3
Learn more about email & git

[PATCH deblob 1/3] io::close can error Export this patch

Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
 main.ha | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/main.ha b/main.ha
index c3724c2..1980c1c 100644
--- a/main.ha
+++ b/main.ha
@@ -24,7 +24,7 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = {
	static let buffer: [512]u8 = [0...];

	const file = os::open(filename)?;
	defer io::close(file);
	defer io::close(file)!;

	const n = match (io::read(file, buffer)?) {
	case let s: size =>
-- 
2.35.1

[PATCH deblob 2/3] Replace fmt::fatal with fmt::fatalf Export this patch

Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
 main.ha | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/main.ha b/main.ha
index 1980c1c..aba99ee 100644
--- a/main.ha
+++ b/main.ha
@@ -57,7 +57,7 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = {
	for (let i = 0z; i < len(tests); i += 1) {
		const result = is_blob(tests[i].0)!;
		if (result != tests[i].1) {
			fmt::fatal("is_blob({}) was incorrect, got {}, expected {}",
			fmt::fatalf("is_blob({}) was incorrect, got {}, expected {}",
				tests[i].0, result, tests[i].1);
		};
	};
@@ -155,7 +155,7 @@ fn check_dir(dirname: str, ignoring: bool) (void | errors::invalid) = {
	case let d: []fs::dirent =>
		yield d;
	case let e: fs::error =>
		fmt::fatal("os::readdir({}): {}", dirname, fs::strerror(e));
		fmt::fatalf("os::readdir({}): {}", dirname, fs::strerror(e));
	};

	const ret = check_dir(dirname, false);
@@ -165,7 +165,7 @@ fn check_dir(dirname: str, ignoring: bool) (void | errors::invalid) = {
	case let d: []fs::dirent =>
		yield d;
	case let e: fs::error =>
		fmt::fatal("os::readdir({}): {}", dirname, fs::strerror(e));
		fmt::fatalf("os::readdir({}): {}", dirname, fs::strerror(e));
	};

	assert(len(files_after) == 5);
@@ -190,7 +190,7 @@ export fn main() void = {
		case 'd' =>
			match (os::chdir(opt.1)) {
			case let e: fs::error =>
				fmt::fatal("os::chdir({}): {}",
				fmt::fatalf("os::chdir({}): {}",
					opt.1, fs::strerror(e));
			case void =>
				void;
-- 
2.35.1

[PATCH deblob 3/3] Simplify is_blob Export this patch

Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
 main.ha | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/main.ha b/main.ha
index aba99ee..5e07869 100644
--- a/main.ha
+++ b/main.ha
@@ -26,10 +26,7 @@ fn is_blob(filename: str) (bool | fs::error | io::error) = {
	const file = os::open(filename)?;
	defer io::close(file)!;

	const n = match (io::read(file, buffer)?) {
	case let s: size =>
		yield s;
	case io::EOF =>
	if (io::readall(file, buffer)? is io::EOF) {
		// empty file
		return false;
	};
-- 
2.35.1