Fossil SCM
Enhance error handling when there is no open checkout and add comments.
Commit
d12fc4b148dcb42fbe79ea7115469368dd575ca4
Parent
9b41960e82af526…
1 file changed
+21
-2
+21
-2
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -1054,12 +1054,31 @@ | ||
| 1054 | 1054 | char *zFull; |
| 1055 | 1055 | int (*xCmp)(const char*,const char*,int); |
| 1056 | 1056 | |
| 1057 | 1057 | blob_zero(pOut); |
| 1058 | 1058 | if( !g.localOpen ){ |
| 1059 | - blob_appendf(pOut, "%s", zOrigName); | |
| 1060 | - return 1; | |
| 1059 | + if( absolute && !file_is_absolute_path(zOrigName) ){ | |
| 1060 | + if( errFatal ){ | |
| 1061 | + fossil_fatal("relative to absolute needs open checkout tree: %s", | |
| 1062 | + zOrigName); | |
| 1063 | + } | |
| 1064 | + return 0; | |
| 1065 | + }else{ | |
| 1066 | + /* | |
| 1067 | + ** The original path may be relative or absolute; however, without | |
| 1068 | + ** an open checkout tree, the only things we can do at this point | |
| 1069 | + ** is return it verbatim or generate a fatal error. The caller is | |
| 1070 | + ** probably expecting a tree-relative path name will be returned; | |
| 1071 | + ** however, most places where this function is called already check | |
| 1072 | + ** if the local checkout tree is open, either directly or indirectly, | |
| 1073 | + ** which would make this situation impossible. Alternatively, they | |
| 1074 | + ** could check the returned path using the file_is_absolute_path() | |
| 1075 | + ** function. | |
| 1076 | + */ | |
| 1077 | + blob_appendf(pOut, "%s", zOrigName); | |
| 1078 | + return 1; | |
| 1079 | + } | |
| 1061 | 1080 | } |
| 1062 | 1081 | file_canonical_name(g.zLocalRoot, &localRoot, 1); |
| 1063 | 1082 | nLocalRoot = blob_size(&localRoot); |
| 1064 | 1083 | zLocalRoot = blob_buffer(&localRoot); |
| 1065 | 1084 | assert( nLocalRoot>0 && zLocalRoot[nLocalRoot-1]=='/' ); |
| 1066 | 1085 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -1054,12 +1054,31 @@ | |
| 1054 | char *zFull; |
| 1055 | int (*xCmp)(const char*,const char*,int); |
| 1056 | |
| 1057 | blob_zero(pOut); |
| 1058 | if( !g.localOpen ){ |
| 1059 | blob_appendf(pOut, "%s", zOrigName); |
| 1060 | return 1; |
| 1061 | } |
| 1062 | file_canonical_name(g.zLocalRoot, &localRoot, 1); |
| 1063 | nLocalRoot = blob_size(&localRoot); |
| 1064 | zLocalRoot = blob_buffer(&localRoot); |
| 1065 | assert( nLocalRoot>0 && zLocalRoot[nLocalRoot-1]=='/' ); |
| 1066 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -1054,12 +1054,31 @@ | |
| 1054 | char *zFull; |
| 1055 | int (*xCmp)(const char*,const char*,int); |
| 1056 | |
| 1057 | blob_zero(pOut); |
| 1058 | if( !g.localOpen ){ |
| 1059 | if( absolute && !file_is_absolute_path(zOrigName) ){ |
| 1060 | if( errFatal ){ |
| 1061 | fossil_fatal("relative to absolute needs open checkout tree: %s", |
| 1062 | zOrigName); |
| 1063 | } |
| 1064 | return 0; |
| 1065 | }else{ |
| 1066 | /* |
| 1067 | ** The original path may be relative or absolute; however, without |
| 1068 | ** an open checkout tree, the only things we can do at this point |
| 1069 | ** is return it verbatim or generate a fatal error. The caller is |
| 1070 | ** probably expecting a tree-relative path name will be returned; |
| 1071 | ** however, most places where this function is called already check |
| 1072 | ** if the local checkout tree is open, either directly or indirectly, |
| 1073 | ** which would make this situation impossible. Alternatively, they |
| 1074 | ** could check the returned path using the file_is_absolute_path() |
| 1075 | ** function. |
| 1076 | */ |
| 1077 | blob_appendf(pOut, "%s", zOrigName); |
| 1078 | return 1; |
| 1079 | } |
| 1080 | } |
| 1081 | file_canonical_name(g.zLocalRoot, &localRoot, 1); |
| 1082 | nLocalRoot = blob_size(&localRoot); |
| 1083 | zLocalRoot = blob_buffer(&localRoot); |
| 1084 | assert( nLocalRoot>0 && zLocalRoot[nLocalRoot-1]=='/' ); |
| 1085 |