8 #include "pbd/compose.h"
11 #include "ardour/session_utils.h"
12 #include "ardour/filename_extensions.h"
13 #include "ardour/utils.h"
21 ARDOUR::find_session (string str, string& path, string& snapshot, bool& isnew)
28 if (!realpath (str.c_str(), buf) && (errno != ENOENT && errno != ENOTDIR)) {
29 error << string_compose (_("Could not resolve path: %1 (%2)"), buf, strerror(errno)) << endmsg;
35 /* check to see if it exists, and what it is */
37 if (stat (str.c_str(), &statbuf)) {
38 if (errno == ENOENT) {
41 error << string_compose (_("cannot check session path %1 (%2)"), str, strerror (errno))
49 /* it exists, so it must either be the name
50 of the directory, or the name of the statefile
54 if (S_ISDIR (statbuf.st_mode)) {
56 string::size_type slash = str.find_last_of ('/');
58 if (slash == string::npos) {
60 /* a subdirectory of cwd, so statefile should be ... */
66 tmp += statefile_suffix;
70 if (stat (tmp.c_str(), &statbuf)) {
71 error << string_compose (_("cannot check statefile %1 (%2)"), tmp, strerror (errno))
81 /* some directory someplace in the filesystem.
82 the snapshot name is the directory name
87 snapshot = str.substr (slash+1);
91 } else if (S_ISREG (statbuf.st_mode)) {
93 string::size_type slash = str.find_last_of ('/');
94 string::size_type suffix;
96 /* remove the suffix */
98 if (slash != string::npos) {
99 snapshot = str.substr (slash+1);
104 suffix = snapshot.find (statefile_suffix);
106 if (suffix == string::npos) {
107 error << string_compose (_("%1 is not an Ardour snapshot file"), str) << endmsg;
113 snapshot = snapshot.substr (0, suffix);
115 if (slash == string::npos) {
117 /* we must be in the directory where the
118 statefile lives. get it using cwd().
121 char cwd[PATH_MAX+1];
123 if (getcwd (cwd, sizeof (cwd)) == 0) {
124 error << string_compose (_("cannot determine current working directory (%1)"), strerror (errno))
133 /* full path to the statefile */
135 path = str.substr (0, slash);
140 /* what type of file is it? */
141 error << string_compose (_("unknown file type for session %1"), str) << endmsg;
147 /* its the name of a new directory. get the name
151 string::size_type slash = str.find_last_of ('/');
153 if (slash == string::npos) {
155 /* no slash, just use the name, but clean it up */
157 path = legalize_for_path (str);
163 snapshot = str.substr (slash+1);