-AudioFileSource::move_to_trash (const ustring& trash_dir_name)
-{
- if (is_embedded()) {
- cerr << "tried to move an embedded region to trash" << endl;
- return -1;
- }
-
- ustring newpath;
-
- if (!writable()) {
- return -1;
- }
-
- /* don't move the file across filesystems, just
- stick it in the `trash_dir_name' directory
- on whichever filesystem it was already on.
- */
-
- newpath = Glib::path_get_dirname (_path);
- newpath = Glib::path_get_dirname (newpath);
-
- cerr << "from " << _path << " dead dir looks like " << newpath << endl;
-
- newpath += '/';
- newpath += trash_dir_name;
- newpath += '/';
- newpath += Glib::path_get_basename (_path);
-
- if (access (newpath.c_str(), F_OK) == 0) {
-
- /* the new path already exists, try versioning */
-
- char buf[PATH_MAX+1];
- int version = 1;
- ustring newpath_v;
-
- snprintf (buf, sizeof (buf), "%s.%d", newpath.c_str(), version);
- newpath_v = buf;
-
- while (access (newpath_v.c_str(), F_OK) == 0 && version < 999) {
- snprintf (buf, sizeof (buf), "%s.%d", newpath.c_str(), ++version);
- newpath_v = buf;
- }
-
- if (version == 999) {
- error << string_compose (_("there are already 1000 files with names like %1; versioning discontinued"),
- newpath)
- << endmsg;
- } else {
- newpath = newpath_v;
- }
-
- } else {
-
- /* it doesn't exist, or we can't read it or something */
-
- }
-
- if (::rename (_path.c_str(), newpath.c_str()) != 0) {
- error << string_compose (_("cannot rename audio file source from %1 to %2 (%3)"),
- _path, newpath, strerror (errno))
- << endmsg;
- return -1;
- }
-
- if (::unlink (peakpath.c_str()) != 0) {
- error << string_compose (_("cannot remove peakfile %1 for %2 (%3)"),
- peakpath, _path, strerror (errno))
- << endmsg;
- /* try to back out */
- rename (newpath.c_str(), _path.c_str());
- return -1;
- }
-
- _path = newpath;
- peakpath = "";
-
- /* file can not be removed twice, since the operation is not idempotent */
-
- _flags = Flag (_flags & ~(RemoveAtDestroy|Removable|RemovableIfEmpty));
-
- return 0;
-}
-
-bool
-AudioFileSource::find (ustring& pathstr, bool must_exist, bool& isnew, uint16_t& chan)
-{
- ustring::size_type pos;
- bool ret = false;
-
- isnew = false;
-
- if (pathstr[0] != '/') {
-
- /* non-absolute pathname: find pathstr in search path */
-
- vector<ustring> dirs;
- int cnt;
- ustring fullpath;
- ustring keeppath;
-
- if (search_path.length() == 0) {
- error << _("FileSource: search path not set") << endmsg;
- goto out;
- }
-
- split (search_path, dirs, ':');
-
- cnt = 0;
-
- for (vector<ustring>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
-
- fullpath = *i;
- if (fullpath[fullpath.length()-1] != '/') {
- fullpath += '/';
- }
-
- fullpath += pathstr;
-
- /* i (paul) made a nasty design error by using ':' as a special character in
- Ardour 0.99 .. this hack tries to make things sort of work.
- */
-
- if ((pos = pathstr.find_last_of (':')) != ustring::npos) {
-
- if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
-
- /* its a real file, no problem */
-
- keeppath = fullpath;
- ++cnt;
-
- } else {
-
- if (must_exist) {
-
- /* might be an older session using file:channel syntax. see if the version
- without the :suffix exists
- */
-
- ustring shorter = pathstr.substr (0, pos);
- fullpath = *i;
-
- if (fullpath[fullpath.length()-1] != '/') {
- fullpath += '/';
- }
-
- fullpath += shorter;
-
- if (Glib::file_test (pathstr, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
- chan = atoi (pathstr.substr (pos+1).c_str());
- pathstr = shorter;
- keeppath = fullpath;
- ++cnt;
- }
-
- } else {
-
- /* new derived file (e.g. for timefx) being created in a newer session */
-
- }
- }
-
- } else {
-
- if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
- keeppath = fullpath;
- ++cnt;
- }
- }
- }
-
- if (cnt > 1) {
-
- error << string_compose (_("FileSource: \"%1\" is ambigous when searching %2\n\t"), pathstr, search_path) << endmsg;
- goto out;
-
- } else if (cnt == 0) {
-
- if (must_exist) {
- error << string_compose(_("Filesource: cannot find required file (%1): while searching %2"), pathstr, search_path) << endmsg;
- goto out;
- } else {
- isnew = true;
- }
- }
-
- _name = pathstr;
- _path = keeppath;
- ret = true;
-
- } else {
-
- /* external files and/or very very old style sessions include full paths */
-
- /* ugh, handle ':' situation */
-
- if ((pos = pathstr.find_last_of (':')) != ustring::npos) {
-
- ustring shorter = pathstr.substr (0, pos);
-
- if (Glib::file_test (shorter, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
- chan = atoi (pathstr.substr (pos+1).c_str());
- pathstr = shorter;
- }
- }
-
- _path = pathstr;
-
- if (is_embedded()) {
- _name = pathstr;
- } else {
- _name = pathstr.substr (pathstr.find_last_of ('/') + 1);
- }
-
- if (!Glib::file_test (pathstr, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
-
- /* file does not exist or we cannot read it */
-
- if (must_exist) {
- error << string_compose(_("Filesource: cannot find required file (%1): %2"), _path, strerror (errno)) << endmsg;
- goto out;
- }
-
- if (errno != ENOENT) {
- error << string_compose(_("Filesource: cannot check for existing file (%1): %2"), _path, strerror (errno)) << endmsg;
- goto out;
- }
-
- /* a new file */
-
- isnew = true;
- ret = true;
-
- } else {
-
- /* already exists */
-
- ret = true;
-
- }
- }
-
- out:
- return ret;
-}
-
-void
-AudioFileSource::set_search_path (ustring p)