- return (sf_command (sf, SFC_UPDATE_HEADER_NOW, 0, 0) != SF_TRUE);
+
+ if (!_open) {
+ warning << string_compose (_("attempt to flush an un-opened audio file source (%1)"), _path) << endmsg;
+ return -1;
+ }
+
+ SNDFILE* sf = _descriptor->allocate ();
+ if (sf == 0) {
+ error << string_compose (_("could not allocate file %1 to write header"), _path) << endmsg;
+ return -1;
+ }
+
+ int const r = sf_command (sf, SFC_UPDATE_HEADER_NOW, 0, 0) != SF_TRUE;
+ _descriptor->release ();
+
+ return r;
+}
+
+void
+SndFileSource::flush ()
+{
+ if (!_open) {
+ warning << string_compose (_("attempt to flush an un-opened audio file source (%1)"), _path) << endmsg;
+ return;
+ }
+
+ if (!writable()) {
+ warning << string_compose (_("attempt to flush a non-writable audio file source (%1)"), _path) << endmsg;
+ return;
+ }
+
+ SNDFILE* sf = _descriptor->allocate ();
+ if (sf == 0) {
+ error << string_compose (_("could not allocate file %1 to flush contents"), _path) << endmsg;
+ return;
+ }
+
+ // Hopefully everything OK
+ sf_write_sync (sf);
+ _descriptor->release ();