[Pkg-privacy-commits] [libgsecuredelete] 14/168: Moved progress file parsing out of DeleteOperation.
Ulrike Uhlig
u-guest at moszumanska.debian.org
Thu Jul 7 20:06:33 UTC 2016
This is an automated email from the git hooks/post-receive script.
u-guest pushed a commit to branch master
in repository libgsecuredelete.
commit 512470c37950df94f5fe1d45f4808763316ac00f
Author: Colomban Wendling <ban at herbesfolles.org>
Date: Wed Sep 30 00:43:31 2009 +0200
Moved progress file parsing out of DeleteOperation.
Moved count of byte occurrence in a file descriptor out from DeleteOperation
as we will need it in other operations.
Added as FD.count_ready_bytes().
---
gsecuredelete/delete-operation.vala | 21 ++-------------------
gsecuredelete/utils.vala | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/gsecuredelete/delete-operation.vala b/gsecuredelete/delete-operation.vala
index 5f97aec..b674d0d 100644
--- a/gsecuredelete/delete-operation.vala
+++ b/gsecuredelete/delete-operation.vala
@@ -100,27 +100,10 @@ namespace SecureDelete
/* gets the progress status of the child process */
private override uint get_progress ()
{
- int fd = this.fd_out;
- size_t bufisze = 16;
- uint progress = 0;
+ uint progress = 0;
try {
- if (FD.read_ready (fd)) {
- char[] buf = new char[bufisze];
- ssize_t read_rv = 0;
-
- do {
- read_rv = Posix.read (fd, buf, bufisze);
- if (read_rv < 0) {
- throw new FDError.READ_ERROR ("read(): %s", strerror (errno));
- } else {
- for (uint i = 0; i < read_rv; i++) {
- if (buf[i] == '*')
- progress ++;
- }
- }
- } while (read_rv == bufisze);
- }
+ progress = FD.count_ready_bytes (this.fd_out, '*');
} catch (FDError e) {
warning ("Progression check failed: %s", e.message);
}
diff --git a/gsecuredelete/utils.vala b/gsecuredelete/utils.vala
index ca1f1cd..2b10a5b 100644
--- a/gsecuredelete/utils.vala
+++ b/gsecuredelete/utils.vala
@@ -122,5 +122,39 @@ namespace SecureDelete
/* pass ownership to the caller */
return (string?) (owned) buf;
}
+
+ /* counts the number of occurrence a given byte in a file descriptor.
+ * This function is non-blocking and returns 0 if there is no
+ * data in the buffer rather than blocking waiting for data to read. */
+ public uint count_ready_bytes (int fd,
+ int byte,
+ size_t bufsize = 16)
+ throws FDError
+ {
+ uint n_occur = 0;
+
+ try {
+ if (FD.read_ready (fd)) {
+ char[] buf = new char[bufsize];
+ ssize_t read_rv = 0;
+
+ do {
+ read_rv = Posix.read (fd, buf, bufsize);
+ if (read_rv < 0) {
+ throw new FDError.READ_ERROR ("read(): %s", strerror (errno));
+ } else {
+ for (uint i = 0; i < read_rv; i++) {
+ if (buf[i] == byte)
+ n_occur ++;
+ }
+ }
+ } while (read_rv == bufsize);
+ }
+ } catch (FDError e) {
+ throw e;
+ }
+
+ return n_occur;
+ }
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libgsecuredelete.git
More information about the Pkg-privacy-commits
mailing list