8 #include "pbd/compose.h"
11 #include "ardour/session_utils.h"
12 #include "ardour/filename_extensions.h"
13 #include "ardour/utils.h"
20 ARDOUR::find_session (string str, string& path, string& snapshot, bool& isnew)
27 if (!realpath (str.c_str(), buf) && (errno != ENOENT && errno != ENOTDIR)) {
28 error << string_compose (_("Could not resolve path: %1 (%2)"), buf, strerror(errno)) << endmsg;
34 /* check to see if it exists, and what it is */
36 if (stat (str.c_str(), &statbuf)) {
37 if (errno == ENOENT) {
40 error << string_compose (_("cannot check session path %1 (%2)"), str, strerror (errno))
48 /* it exists, so it must either be the name
49 of the directory, or the name of the statefile
53 if (S_ISDIR (statbuf.st_mode)) {
55 string::size_type slash = str.find_last_of ('/');
57 if (slash == string::npos) {
59 /* a subdirectory of cwd, so statefile should be ... */
65 tmp += statefile_suffix;
69 if (stat (tmp.c_str(), &statbuf)) {
70 error << string_compose (_("cannot check statefile %1 (%2)"), tmp, strerror (errno))
80 /* some directory someplace in the filesystem.
81 the snapshot name is the directory name
86 snapshot = str.substr (slash+1);
90 } else if (S_ISREG (statbuf.st_mode)) {
92 string::size_type slash = str.find_last_of ('/');
93 string::size_type suffix;
95 /* remove the suffix */
97 if (slash != string::npos) {
98 snapshot = str.substr (slash+1);
103 suffix = snapshot.find (statefile_suffix);
105 if (suffix == string::npos) {
106 error << string_compose (_("%1 is not an Ardour snapshot file"), str) << endmsg;
112 snapshot = snapshot.substr (0, suffix);
114 if (slash == string::npos) {
116 /* we must be in the directory where the
117 statefile lives. get it using cwd().
120 char cwd[PATH_MAX+1];
122 if (getcwd (cwd, sizeof (cwd)) == 0) {
123 error << string_compose (_("cannot determine current working directory (%1)"), strerror (errno))
132 /* full path to the statefile */
134 path = str.substr (0, slash);
139 /* what type of file is it? */
140 error << string_compose (_("unknown file type for session %1"), str) << endmsg;
146 /* its the name of a new directory. get the name
150 string::size_type slash = str.find_last_of ('/');
152 if (slash == string::npos) {
154 /* no slash, just use the name, but clean it up */
156 path = legalize_for_path (str);
162 snapshot = str.substr (slash+1);