Fossil SCM
Move manifest.symlinks read functionality into the new get_checkout_symlink_table() function in checkout.c
Commit
7a4bd5cf830693d03a2c11a64153d5680480dd80e7d544d28b344e1cbfe894a6
Parent
2808e225964e503…
2 files changed
+5
-35
+57
+5
-35
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -1500,44 +1500,14 @@ | ||
| 1500 | 1500 | ManifestFile *pFile; /* File from the baseline */ |
| 1501 | 1501 | int nFBcard = 0; /* Number of B-cards and F-cards */ |
| 1502 | 1502 | int i; /* Loop counter */ |
| 1503 | 1503 | const char *zColor; /* Modified value of p->zColor */ |
| 1504 | 1504 | |
| 1505 | + /* On Windows, get symlink permission status from the "manifest.symlinks" file | |
| 1506 | + * if it exists and if the "manifest" setting contains the "l" flag. */ | |
| 1505 | 1507 | #ifdef _WIN32 |
| 1506 | - /* On Windows, if the "manifest" setting contains the "l" flag, get the | |
| 1507 | - * symlink status bits from the "manifest.symlinks" file. */ | |
| 1508 | - int manifestSymlinks = db_get_manifest_setting() & MFESTFLG_SYMLINKS; | |
| 1509 | - if( manifestSymlinks ){ | |
| 1510 | - char *zFile = mprintf("%smanifest.symlinks", g.zLocalRoot); | |
| 1511 | - if( file_wd_size(zFile)>=0 ){ | |
| 1512 | - /* If the file exists, read its contents into a temporary table. */ | |
| 1513 | - char *zLine, *zEnd; | |
| 1514 | - Blob content = BLOB_INITIALIZER; | |
| 1515 | - blob_read_from_file(&content, zFile); | |
| 1516 | - blob_append(&content, "\n", 2); | |
| 1517 | - db_multi_exec("CREATE TEMP TABLE symlink(filename TEXT PRIMARY KEY %s)", | |
| 1518 | - filename_collation()); | |
| 1519 | - zLine = blob_buffer(&content); | |
| 1520 | - while( *zLine ){ | |
| 1521 | - /* Find end of line and replace with NUL. */ | |
| 1522 | - for( zEnd = zLine; *zEnd!='\r' && *zEnd!='\n'; ++zEnd ); | |
| 1523 | - *zEnd = 0; | |
| 1524 | - | |
| 1525 | - /* If not a blank line, insert filename into symlink table. */ | |
| 1526 | - if( *zLine ){ | |
| 1527 | - db_multi_exec("INSERT OR IGNORE INTO symlink VALUES(%Q)", zLine); | |
| 1528 | - } | |
| 1529 | - | |
| 1530 | - /* Find start of next line, or find terminating NUL at end of file. */ | |
| 1531 | - for( zLine = zEnd+1; *zLine=='\r' || *zLine=='\n'; ++zLine ); | |
| 1532 | - } | |
| 1533 | - blob_reset(&content); | |
| 1534 | - }else{ | |
| 1535 | - /* If the file is nonexistent, pretend the "l" flag was not specified. */ | |
| 1536 | - manifestSymlinks = 0; | |
| 1537 | - } | |
| 1538 | - } | |
| 1508 | + int manifestSymlinks = get_checkout_symlink_table(); | |
| 1539 | 1509 | #endif |
| 1540 | 1510 | |
| 1541 | 1511 | assert( pBaseline==0 || pBaseline->zBaseline==0 ); |
| 1542 | 1512 | assert( pBaseline==0 || zBaselineUuid!=0 ); |
| 1543 | 1513 | blob_zero(pOut); |
| @@ -1593,14 +1563,14 @@ | ||
| 1593 | 1563 | |
| 1594 | 1564 | /* Potentially update the permissions of files selected to be checked in. */ |
| 1595 | 1565 | #ifdef _WIN32 |
| 1596 | 1566 | /* For Windows, if the "manifest" setting contains the "l" flag and the |
| 1597 | 1567 | ** "manifest.symlinks" file exists, use its contents to determine which |
| 1598 | - ** files do and do not have the "symlink" permission. | |
| 1568 | + ** files do and do not have the symlink permission. | |
| 1599 | 1569 | */ |
| 1600 | 1570 | if( isSelected && manifestSymlinks ){ |
| 1601 | - isLink = db_exists("SELECT 1 FROM symlink WHERE filename=%Q", zName); | |
| 1571 | + isLink = db_exists("SELECT 1 FROM symlink_perm WHERE filename=%Q", zName); | |
| 1602 | 1572 | } |
| 1603 | 1573 | #else |
| 1604 | 1574 | /* For unix, extract the "executable" and "symlink" permissions |
| 1605 | 1575 | ** directly from the filesystem. On windows, permissions are |
| 1606 | 1576 | ** unchanged from the original. |
| 1607 | 1577 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1500,44 +1500,14 @@ | |
| 1500 | ManifestFile *pFile; /* File from the baseline */ |
| 1501 | int nFBcard = 0; /* Number of B-cards and F-cards */ |
| 1502 | int i; /* Loop counter */ |
| 1503 | const char *zColor; /* Modified value of p->zColor */ |
| 1504 | |
| 1505 | #ifdef _WIN32 |
| 1506 | /* On Windows, if the "manifest" setting contains the "l" flag, get the |
| 1507 | * symlink status bits from the "manifest.symlinks" file. */ |
| 1508 | int manifestSymlinks = db_get_manifest_setting() & MFESTFLG_SYMLINKS; |
| 1509 | if( manifestSymlinks ){ |
| 1510 | char *zFile = mprintf("%smanifest.symlinks", g.zLocalRoot); |
| 1511 | if( file_wd_size(zFile)>=0 ){ |
| 1512 | /* If the file exists, read its contents into a temporary table. */ |
| 1513 | char *zLine, *zEnd; |
| 1514 | Blob content = BLOB_INITIALIZER; |
| 1515 | blob_read_from_file(&content, zFile); |
| 1516 | blob_append(&content, "\n", 2); |
| 1517 | db_multi_exec("CREATE TEMP TABLE symlink(filename TEXT PRIMARY KEY %s)", |
| 1518 | filename_collation()); |
| 1519 | zLine = blob_buffer(&content); |
| 1520 | while( *zLine ){ |
| 1521 | /* Find end of line and replace with NUL. */ |
| 1522 | for( zEnd = zLine; *zEnd!='\r' && *zEnd!='\n'; ++zEnd ); |
| 1523 | *zEnd = 0; |
| 1524 | |
| 1525 | /* If not a blank line, insert filename into symlink table. */ |
| 1526 | if( *zLine ){ |
| 1527 | db_multi_exec("INSERT OR IGNORE INTO symlink VALUES(%Q)", zLine); |
| 1528 | } |
| 1529 | |
| 1530 | /* Find start of next line, or find terminating NUL at end of file. */ |
| 1531 | for( zLine = zEnd+1; *zLine=='\r' || *zLine=='\n'; ++zLine ); |
| 1532 | } |
| 1533 | blob_reset(&content); |
| 1534 | }else{ |
| 1535 | /* If the file is nonexistent, pretend the "l" flag was not specified. */ |
| 1536 | manifestSymlinks = 0; |
| 1537 | } |
| 1538 | } |
| 1539 | #endif |
| 1540 | |
| 1541 | assert( pBaseline==0 || pBaseline->zBaseline==0 ); |
| 1542 | assert( pBaseline==0 || zBaselineUuid!=0 ); |
| 1543 | blob_zero(pOut); |
| @@ -1593,14 +1563,14 @@ | |
| 1593 | |
| 1594 | /* Potentially update the permissions of files selected to be checked in. */ |
| 1595 | #ifdef _WIN32 |
| 1596 | /* For Windows, if the "manifest" setting contains the "l" flag and the |
| 1597 | ** "manifest.symlinks" file exists, use its contents to determine which |
| 1598 | ** files do and do not have the "symlink" permission. |
| 1599 | */ |
| 1600 | if( isSelected && manifestSymlinks ){ |
| 1601 | isLink = db_exists("SELECT 1 FROM symlink WHERE filename=%Q", zName); |
| 1602 | } |
| 1603 | #else |
| 1604 | /* For unix, extract the "executable" and "symlink" permissions |
| 1605 | ** directly from the filesystem. On windows, permissions are |
| 1606 | ** unchanged from the original. |
| 1607 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1500,44 +1500,14 @@ | |
| 1500 | ManifestFile *pFile; /* File from the baseline */ |
| 1501 | int nFBcard = 0; /* Number of B-cards and F-cards */ |
| 1502 | int i; /* Loop counter */ |
| 1503 | const char *zColor; /* Modified value of p->zColor */ |
| 1504 | |
| 1505 | /* On Windows, get symlink permission status from the "manifest.symlinks" file |
| 1506 | * if it exists and if the "manifest" setting contains the "l" flag. */ |
| 1507 | #ifdef _WIN32 |
| 1508 | int manifestSymlinks = get_checkout_symlink_table(); |
| 1509 | #endif |
| 1510 | |
| 1511 | assert( pBaseline==0 || pBaseline->zBaseline==0 ); |
| 1512 | assert( pBaseline==0 || zBaselineUuid!=0 ); |
| 1513 | blob_zero(pOut); |
| @@ -1593,14 +1563,14 @@ | |
| 1563 | |
| 1564 | /* Potentially update the permissions of files selected to be checked in. */ |
| 1565 | #ifdef _WIN32 |
| 1566 | /* For Windows, if the "manifest" setting contains the "l" flag and the |
| 1567 | ** "manifest.symlinks" file exists, use its contents to determine which |
| 1568 | ** files do and do not have the symlink permission. |
| 1569 | */ |
| 1570 | if( isSelected && manifestSymlinks ){ |
| 1571 | isLink = db_exists("SELECT 1 FROM symlink_perm WHERE filename=%Q", zName); |
| 1572 | } |
| 1573 | #else |
| 1574 | /* For unix, extract the "executable" and "symlink" permissions |
| 1575 | ** directly from the filesystem. On windows, permissions are |
| 1576 | ** unchanged from the original. |
| 1577 |
+57
| --- src/checkout.c | ||
| +++ src/checkout.c | ||
| @@ -247,10 +247,67 @@ | ||
| 247 | 247 | blob_appendf(pOut, "%s\n", pFile->zName); |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | manifest_destroy(pManifest); |
| 251 | 251 | } |
| 252 | + | |
| 253 | +#ifdef _WIN32 | |
| 254 | +/* | |
| 255 | +** Create a temporary table called "symlink_perm" containing the names of all | |
| 256 | +** files considered to be symlinks. This function only exists in Windows | |
| 257 | +** because Unix symlink status comes directly from the filesystem. The return | |
| 258 | +** value is 1 if the table was created or 0 if symlink status is to be inherited | |
| 259 | +** from the baseline check-in manifest. The latter case occurs when the file | |
| 260 | +** does not exist or when the "manifest" setting does not contain the "l" flag. | |
| 261 | +*/ | |
| 262 | +int get_checkout_symlink_table(void){ | |
| 263 | + Blob content = BLOB_INITIALIZER; | |
| 264 | + char *zFile, *zLine, *zEnd; | |
| 265 | + | |
| 266 | + /* If the "manifest" setting lacks the "l" flag, do no further processing. | |
| 267 | + * Symlink status will be inherited from the previous check-in. */ | |
| 268 | + if( !(db_get_manifest_setting() & MFESTFLG_SYMLINKS) ){ | |
| 269 | + return 0; | |
| 270 | + } | |
| 271 | + | |
| 272 | + /* If the "manifest.symlinks" file does not exist, act as if the "manifest" | |
| 273 | + * setting didn't have "l". The file will be regenerated with the next commit | |
| 274 | + * or update, but for now, temporarily disable symlink status updating. */ | |
| 275 | + zFile = mprintf("%smanifest.symlinks", g.zLocalRoot); | |
| 276 | + if( file_wd_size(zFile)<0 ){ | |
| 277 | + return 0; | |
| 278 | + } | |
| 279 | + | |
| 280 | + /* Read "manifest.symlinks" into a blob to be analyzed. Simplify processing | |
| 281 | + * by forcing it to end with newline-NUL. */ | |
| 282 | + blob_read_from_file(&content, zFile); | |
| 283 | + blob_append(&content, "\n", 2); | |
| 284 | + zLine = blob_buffer(&content); | |
| 285 | + | |
| 286 | + /* Insert each non-empty line of "manifest.symlinks" into the "symlink_perm" | |
| 287 | + * temporary table. */ | |
| 288 | + db_multi_exec("CREATE TEMP TABLE symlink_perm(filename TEXT PRIMARY KEY %s)", | |
| 289 | + filename_collation()); | |
| 290 | + while( *zLine ){ | |
| 291 | + /* Find end of line and replace with NUL. */ | |
| 292 | + for( zEnd = zLine; *zEnd!='\r' && *zEnd!='\n'; ++zEnd ); | |
| 293 | + *zEnd = 0; | |
| 294 | + | |
| 295 | + /* If not a blank line, insert filename into symlink table. */ | |
| 296 | + if( *zLine ){ | |
| 297 | + db_multi_exec("INSERT OR IGNORE INTO symlink_perm VALUES(%Q)", zLine); | |
| 298 | + } | |
| 299 | + | |
| 300 | + /* Find start of next line, or find terminating NUL at end of file. */ | |
| 301 | + for( zLine = zEnd+1; *zLine=='\r' || *zLine=='\n'; ++zLine ); | |
| 302 | + } | |
| 303 | + blob_reset(&content); | |
| 304 | + | |
| 305 | + /* Let the caller know the "symlink_perm" table was created and is valid. */ | |
| 306 | + return 1; | |
| 307 | +} | |
| 308 | +#endif | |
| 252 | 309 | |
| 253 | 310 | /* |
| 254 | 311 | ** COMMAND: checkout* |
| 255 | 312 | ** COMMAND: co* |
| 256 | 313 | ** |
| 257 | 314 |
| --- src/checkout.c | |
| +++ src/checkout.c | |
| @@ -247,10 +247,67 @@ | |
| 247 | blob_appendf(pOut, "%s\n", pFile->zName); |
| 248 | } |
| 249 | } |
| 250 | manifest_destroy(pManifest); |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | ** COMMAND: checkout* |
| 255 | ** COMMAND: co* |
| 256 | ** |
| 257 |
| --- src/checkout.c | |
| +++ src/checkout.c | |
| @@ -247,10 +247,67 @@ | |
| 247 | blob_appendf(pOut, "%s\n", pFile->zName); |
| 248 | } |
| 249 | } |
| 250 | manifest_destroy(pManifest); |
| 251 | } |
| 252 | |
| 253 | #ifdef _WIN32 |
| 254 | /* |
| 255 | ** Create a temporary table called "symlink_perm" containing the names of all |
| 256 | ** files considered to be symlinks. This function only exists in Windows |
| 257 | ** because Unix symlink status comes directly from the filesystem. The return |
| 258 | ** value is 1 if the table was created or 0 if symlink status is to be inherited |
| 259 | ** from the baseline check-in manifest. The latter case occurs when the file |
| 260 | ** does not exist or when the "manifest" setting does not contain the "l" flag. |
| 261 | */ |
| 262 | int get_checkout_symlink_table(void){ |
| 263 | Blob content = BLOB_INITIALIZER; |
| 264 | char *zFile, *zLine, *zEnd; |
| 265 | |
| 266 | /* If the "manifest" setting lacks the "l" flag, do no further processing. |
| 267 | * Symlink status will be inherited from the previous check-in. */ |
| 268 | if( !(db_get_manifest_setting() & MFESTFLG_SYMLINKS) ){ |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | /* If the "manifest.symlinks" file does not exist, act as if the "manifest" |
| 273 | * setting didn't have "l". The file will be regenerated with the next commit |
| 274 | * or update, but for now, temporarily disable symlink status updating. */ |
| 275 | zFile = mprintf("%smanifest.symlinks", g.zLocalRoot); |
| 276 | if( file_wd_size(zFile)<0 ){ |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | /* Read "manifest.symlinks" into a blob to be analyzed. Simplify processing |
| 281 | * by forcing it to end with newline-NUL. */ |
| 282 | blob_read_from_file(&content, zFile); |
| 283 | blob_append(&content, "\n", 2); |
| 284 | zLine = blob_buffer(&content); |
| 285 | |
| 286 | /* Insert each non-empty line of "manifest.symlinks" into the "symlink_perm" |
| 287 | * temporary table. */ |
| 288 | db_multi_exec("CREATE TEMP TABLE symlink_perm(filename TEXT PRIMARY KEY %s)", |
| 289 | filename_collation()); |
| 290 | while( *zLine ){ |
| 291 | /* Find end of line and replace with NUL. */ |
| 292 | for( zEnd = zLine; *zEnd!='\r' && *zEnd!='\n'; ++zEnd ); |
| 293 | *zEnd = 0; |
| 294 | |
| 295 | /* If not a blank line, insert filename into symlink table. */ |
| 296 | if( *zLine ){ |
| 297 | db_multi_exec("INSERT OR IGNORE INTO symlink_perm VALUES(%Q)", zLine); |
| 298 | } |
| 299 | |
| 300 | /* Find start of next line, or find terminating NUL at end of file. */ |
| 301 | for( zLine = zEnd+1; *zLine=='\r' || *zLine=='\n'; ++zLine ); |
| 302 | } |
| 303 | blob_reset(&content); |
| 304 | |
| 305 | /* Let the caller know the "symlink_perm" table was created and is valid. */ |
| 306 | return 1; |
| 307 | } |
| 308 | #endif |
| 309 | |
| 310 | /* |
| 311 | ** COMMAND: checkout* |
| 312 | ** COMMAND: co* |
| 313 | ** |
| 314 |