summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qarshd.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/qarshd.c b/qarshd.c
index ccfd339..345f6de 100644
--- a/qarshd.c
+++ b/qarshd.c
@@ -51,6 +51,11 @@ int debug = 0;
struct sockaddr_in peername;
int child_exitted = 0;
+/* A mini cache for rstat so we can check it in pushfile */
+char *saved_path = NULL;
+struct stat saved_stat;
+
+
int
setup_user(char *user, char *group)
{
@@ -196,22 +201,32 @@ pushfile(const char *path, int of_port)
return -1;
}
- if (fstat(infd, &sb) < 0) {
+ if (strcmp(saved_path, path) == 0) {
+ nbytes = sendfile(outsd, infd, &offset, saved_stat.st_size);
+ } else if (fstat(infd, &sb) < 0) {
syslog(LOG_WARNING, "Could not stat %s: %s\n",
path, strerror(errno));
close(infd);
close(outsd);
return -1;
+ } else { /* fstat filled in sb */
+ nbytes = sendfile(outsd, infd, &offset, sb.st_size);
}
- nbytes = sendfile(outsd, infd, &offset, sb.st_size);
-
close(infd);
close(outsd);
return nbytes;
}
+void
+save_stat(const char *path, const struct stat *sb)
+{
+ if (saved_path) free(saved_path);
+ saved_path = strdup(path);
+ memcpy(&saved_stat, sb, sizeof saved_stat);
+}
+
struct qa_packet *
rstat(const char *path)
{
@@ -223,6 +238,7 @@ rstat(const char *path)
} else {
rp = make_qp_rstat(path, &sb);
}
+ save_stat(path, &sb);
return rp;
}