shithub: vdir

Download patch

ref: 2bab9ca96b1aef62b5a83b2cda600517d40b5758
parent: 15873bca502ea7210ab3347a1816075f0e190183
author: telephil9 <telephil9@gmail.com>
date: Sat Apr 4 07:32:52 EDT 2020

Report errors through alert popups

--- a/vdir.c
+++ b/vdir.c
@@ -6,6 +6,9 @@
 #include <plumb.h>
 #include <bio.h>
 #include "icons.h"
+
+extern void alert(const char *title, const char *message);
+
 enum
 {
 	Toolpadding = 4,
@@ -44,7 +47,15 @@
 int nlines;
 int offset;
 
+void
+showerrstr(void)
+{
+	char errbuf[ERRMAX];
 
+	errstr(errbuf, ERRMAX-1);
+	alert("Error", errbuf);
+}
+
 void
 readhome(void)
 {
@@ -123,11 +134,15 @@
 	int fd;
 
 	p = smprint("%s/%s", path, name);
-	if(access(p, 0)>=0)
+	if(access(p, 0)>=0){
+		alert("Error", "Directory already exists");
 		goto cleanup;
+	}
 	fd = create(p, OREAD, DMDIR|0755);
-	if(fd<0)
-		goto cleanup; /* XXX error report */
+	if(fd<0){
+		showerrstr();
+		goto cleanup;
+	}
 	close(fd);
 	loaddirs();
 cleanup:
@@ -141,11 +156,15 @@
 	int fd;
 
 	p = smprint("%s/%s", path, name);
-	if(access(p, 0)>=0)
+	if(access(p, 0)>=0){
+		alert("Error", "File already exists");
 		goto cleanup;
+	}
 	fd = create(p, OREAD, 0644);
-	if(fd<0)
-		goto cleanup; /* XXX error report */
+	if(fd<0){
+		showerrstr();
+		goto cleanup;
+	}
 	close(fd);
 	loaddirs();
 cleanup: