#endif
#include "pbd/compose.h"
+#include "pbd/file_manager.h"
#include "pbd/file_utils.h"
#include "pbd/debug.h"
#include "pbd/error.h"
{
if (!Glib::file_test (from_path, Glib::FILE_TEST_EXISTS)) return false;
- int fd_from = -1;
- int fd_to = -1;
+ FdFileDescriptor from_file(from_path, false, 0444);
+ FdFileDescriptor to_file(to_path, true, 0666);
+
+ int fd_from = from_file.allocate ();
+ int fd_to = to_file.allocate ();
char buf[4096]; // BUFSIZ ??
ssize_t nread;
- fd_from = ::open(from_path.c_str(), O_RDONLY);
- if (fd_from < 0) {
- goto copy_error;
- }
-
- fd_to = ::open(to_path.c_str(), O_WRONLY | O_CREAT, 0666);
- if (fd_to < 0) {
- goto copy_error;
+ if ((fd_from < 0) || (fd_to < 0)) {
+ error << string_compose (_("Unable to Open files %1 to %2 for Copying(%3)"),
+ from_path, to_path, g_strerror(errno))
+ << endmsg;
+ return false;
}
while (nread = ::read(fd_from, buf, sizeof(buf)), nread > 0) {
nread -= nwritten;
out_ptr += nwritten;
} else if (errno != EINTR) {
- goto copy_error;
+ error << string_compose (_("Unable to Copy files %1 to %2(%3)"),
+ from_path, to_path, g_strerror(errno))
+ << endmsg;
+ return false;
}
} while (nread > 0);
}
- if (nread == 0) {
- if (::close(fd_to)) {
- fd_to = -1;
- goto copy_error;
- }
- ::close(fd_from);
- return true;
- }
-
-copy_error:
- int saved_errno = errno;
-
- if (fd_from >= 0) {
- ::close(fd_from);
- }
- if (fd_to >= 0) {
- ::close(fd_to);
- }
-
- error << string_compose (_("Unable to Copy file %1 to %2 (%3)"),
- from_path, to_path, strerror(saved_errno))
- << endmsg;
- return false;
+ return true;
}
void
return Glib::build_filename (Glib::get_current_dir(), p);
}
+std::string
+get_suffix (const std::string & p)
+{
+ string::size_type period = p.find_last_of ('.');
+ if (period == string::npos || period == p.length() - 1) {
+ return string();
+ }
+ return p.substr (period+1);
+}
+
bool
equivalent_paths (const std::string& a, const std::string& b)
{
bool just_remove_files)
{
vector<string> tmp_paths;
- struct stat statbuf;
+ GStatBuf statbuf;
int ret = 0;
get_paths (tmp_paths, dir, just_remove_files, true);