X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Ffind_session.cc;h=c470ef7f3e9a0ace591f02f2db84a456355e9d01;hb=79621762193a7a56cbb5a966cc8603c1d1c5e17c;hp=c635b86545ad442c457d76d6290f0c0e9fa76f91;hpb=a5e74a774c6e1b39672392e26ee48385c4ac0034;p=ardour.git diff --git a/libs/ardour/find_session.cc b/libs/ardour/find_session.cc index c635b86545..c470ef7f3e 100644 --- a/libs/ardour/find_session.cc +++ b/libs/ardour/find_session.cc @@ -1,42 +1,59 @@ +/* + Copyright (C) 2012 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #include -#include #include #include #include +#include "pbd/gstdio_compat.h" + #include #include "pbd/compose.h" +#include "pbd/pathexpand.h" #include "pbd/error.h" -#include "ardour/session_utils.h" #include "ardour/filename_extensions.h" #include "ardour/utils.h" +#include "ardour/session_utils.h" #include "i18n.h" using namespace std; using namespace PBD; +namespace ARDOUR { + int -ARDOUR::find_session (string str, string& path, string& snapshot, bool& isnew) +find_session (string str, string& path, string& snapshot, bool& isnew) { - struct stat statbuf; - char buf[PATH_MAX+1]; + GStatBuf statbuf; isnew = false; - if (!realpath (str.c_str(), buf) && (errno != ENOENT && errno != ENOTDIR)) { - error << string_compose (_("Could not resolve path: %1 (%2)"), buf, strerror(errno)) << endmsg; - return -1; - } - - str = buf; + str = canonical_path (str); /* check to see if it exists, and what it is */ - if (stat (str.c_str(), &statbuf)) { + if (g_stat (str.c_str(), &statbuf)) { if (errno == ENOENT) { isnew = true; } else { @@ -65,7 +82,7 @@ ARDOUR::find_session (string str, string& path, string& snapshot, bool& isnew) /* is it there ? */ - if (stat (tmp.c_str(), &statbuf)) { + if (g_stat (tmp.c_str(), &statbuf)) { error << string_compose (_("cannot check statefile %1 (%2)"), tmp, strerror (errno)) << endmsg; return -1; @@ -101,7 +118,10 @@ ARDOUR::find_session (string str, string& path, string& snapshot, bool& isnew) suffix = snapshot.find (statefile_suffix); - if (suffix == string::npos) { + const string::size_type start_pos_of_extension = snapshot.size () - strlen (statefile_suffix); + // we should check the start of extension position + // because files '*.ardour.bak' are possible + if (suffix != start_pos_of_extension) { error << string_compose (_("%1 is not a snapshot file"), str) << endmsg; return -1; } @@ -164,3 +184,5 @@ ARDOUR::find_session (string str, string& path, string& snapshot, bool& isnew) return 0; } + +} // namespace ARDOUR