|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.30 2000/01/26 05:56:10 momjian Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.31 2000/04/09 04:43:15 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
|
23 | 23 | #include "utils/syscache.h"
|
24 | 24 |
|
25 | 25 | /*
|
26 |
| - * relpath - path to the relation |
27 |
| - * Perhaps this should be in-line code in relopen(). |
| 26 | + * relpath - construct path to a relation's file |
| 27 | + * |
| 28 | + * Note that this only works with relations that are visible to the current |
| 29 | + * backend, ie, either in the current database or shared system relations. |
| 30 | + * |
| 31 | + * Result is a palloc'd string. |
28 | 32 | */
|
29 | 33 | char *
|
30 | 34 | relpath(const char *relname)
|
31 | 35 | {
|
32 | 36 | char *path;
|
33 |
| - size_t bufsize = 0; |
34 | 37 |
|
35 | 38 | if (IsSharedSystemRelationName(relname))
|
36 | 39 | {
|
37 |
| - bufsize = strlen(DataDir) + sizeof(NameData) + 2; |
| 40 | + /* Shared system relations live in DataDir */ |
| 41 | + size_t bufsize = strlen(DataDir) + sizeof(NameData) + 2; |
| 42 | + |
38 | 43 | path = (char *) palloc(bufsize);
|
39 |
| - snprintf(path, bufsize, "%s/%s", DataDir, relname); |
| 44 | + snprintf(path, bufsize, "%s%c%s", DataDir, SEP_CHAR, relname); |
40 | 45 | return path;
|
41 | 46 | }
|
| 47 | + /* |
| 48 | + * If it is in the current database, assume it is in current working |
| 49 | + * directory. NB: this does not work during bootstrap! |
| 50 | + */ |
42 | 51 | return pstrdup(relname);
|
43 | 52 | }
|
44 | 53 |
|
| 54 | +/* |
| 55 | + * relpath_blind - construct path to a relation's file |
| 56 | + * |
| 57 | + * Construct the path using only the info available to smgrblindwrt, |
| 58 | + * namely the names and OIDs of the database and relation. (Shared system |
| 59 | + * relations are identified with dbid = 0.) Note that we may have to |
| 60 | + * access a relation belonging to a different database! |
| 61 | + * |
| 62 | + * Result is a palloc'd string. |
| 63 | + */ |
| 64 | + |
| 65 | +char * |
| 66 | +relpath_blind(const char *dbname, const char *relname, |
| 67 | + Oid dbid, Oid relid) |
| 68 | +{ |
| 69 | + char *path; |
| 70 | + |
| 71 | + if (dbid == (Oid) 0) |
| 72 | + { |
| 73 | + /* Shared system relations live in DataDir */ |
| 74 | + path = (char *) palloc(strlen(DataDir) + sizeof(NameData) + 2); |
| 75 | + sprintf(path, "%s%c%s", DataDir, SEP_CHAR, relname); |
| 76 | + } |
| 77 | + else if (dbid == MyDatabaseId) |
| 78 | + { |
| 79 | + /* XXX why is this inconsistent with relpath() ? */ |
| 80 | + path = (char *) palloc(strlen(DatabasePath) + sizeof(NameData) + 2); |
| 81 | + sprintf(path, "%s%c%s", DatabasePath, SEP_CHAR, relname); |
| 82 | + } |
| 83 | + else |
| 84 | + { |
| 85 | + /* this is work around only !!! */ |
| 86 | + char dbpathtmp[MAXPGPATH]; |
| 87 | + Oid id; |
| 88 | + char *dbpath; |
| 89 | + |
| 90 | + GetRawDatabaseInfo(dbname, &id, dbpathtmp); |
| 91 | + |
| 92 | + if (id != dbid) |
| 93 | + elog(FATAL, "relpath_blind: oid of db %s is not %u", |
| 94 | + dbname, dbid); |
| 95 | + dbpath = ExpandDatabasePath(dbpathtmp); |
| 96 | + if (dbpath == NULL) |
| 97 | + elog(FATAL, "relpath_blind: can't expand path for db %s", |
| 98 | + dbname); |
| 99 | + path = (char *) palloc(strlen(dbpath) + sizeof(NameData) + 2); |
| 100 | + sprintf(path, "%s%c%s", dbpath, SEP_CHAR, relname); |
| 101 | + pfree(dbpath); |
| 102 | + } |
| 103 | + return path; |
| 104 | +} |
| 105 | + |
| 106 | + |
45 | 107 | /*
|
46 | 108 | * IsSystemRelationName
|
47 | 109 | * True iff name is the name of a system catalog relation.
|
|
0 commit comments