Fossil SCM
Introduce constants for internal permissions (executable/symlink).
Commit
f6daee3e7be36e7b435b116941ae3d9c68e6dabe
Parent
72e3bbd0710eb85…
7 files changed
+5
-6
+5
-8
+10
-3
+3
-2
+2
-2
+2
-2
+5
-6
+5
-6
| --- src/export.c | ||
| +++ src/export.c | ||
| @@ -271,16 +271,15 @@ | ||
| 271 | 271 | int mPerm = db_column_int(&q4,2); |
| 272 | 272 | if( zNew==0) |
| 273 | 273 | printf("D %s\n", zName); |
| 274 | 274 | else if( bag_find(&blobs, zNew) ) { |
| 275 | 275 | const char *zPerm; |
| 276 | - if( mPerm==1 ) | |
| 277 | - zPerm = "100755"; | |
| 278 | - else if( mPerm==2 ) | |
| 279 | - zPerm = "120000"; | |
| 280 | - else | |
| 281 | - zPerm = "100644"; | |
| 276 | + switch( mPerm ){ | |
| 277 | + case PERM_LNK: zPerm = "120000"; break; | |
| 278 | + case PERM_EXE: zPerm = "100755"; break; | |
| 279 | + default: zPerm = "100644"; break; | |
| 280 | + } | |
| 282 | 281 | printf("M %s :%d %s\n", zPerm, BLOBMARK(zNew), zName); |
| 283 | 282 | } |
| 284 | 283 | } |
| 285 | 284 | db_finalize(&q4); |
| 286 | 285 | db_finalize(&q3); |
| 287 | 286 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -271,16 +271,15 @@ | |
| 271 | int mPerm = db_column_int(&q4,2); |
| 272 | if( zNew==0) |
| 273 | printf("D %s\n", zName); |
| 274 | else if( bag_find(&blobs, zNew) ) { |
| 275 | const char *zPerm; |
| 276 | if( mPerm==1 ) |
| 277 | zPerm = "100755"; |
| 278 | else if( mPerm==2 ) |
| 279 | zPerm = "120000"; |
| 280 | else |
| 281 | zPerm = "100644"; |
| 282 | printf("M %s :%d %s\n", zPerm, BLOBMARK(zNew), zName); |
| 283 | } |
| 284 | } |
| 285 | db_finalize(&q4); |
| 286 | db_finalize(&q3); |
| 287 |
| --- src/export.c | |
| +++ src/export.c | |
| @@ -271,16 +271,15 @@ | |
| 271 | int mPerm = db_column_int(&q4,2); |
| 272 | if( zNew==0) |
| 273 | printf("D %s\n", zName); |
| 274 | else if( bag_find(&blobs, zNew) ) { |
| 275 | const char *zPerm; |
| 276 | switch( mPerm ){ |
| 277 | case PERM_LNK: zPerm = "120000"; break; |
| 278 | case PERM_EXE: zPerm = "100755"; break; |
| 279 | default: zPerm = "100644"; break; |
| 280 | } |
| 281 | printf("M %s :%d %s\n", zPerm, BLOBMARK(zNew), zName); |
| 282 | } |
| 283 | } |
| 284 | db_finalize(&q4); |
| 285 | db_finalize(&q3); |
| 286 |
+5
-8
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -199,22 +199,19 @@ | ||
| 199 | 199 | #endif |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | |
| 203 | 203 | /* |
| 204 | -** Return file "permissions": | |
| 205 | -** 0: normal | |
| 206 | -** 1: exec | |
| 207 | -** 2: symlink | |
| 204 | +** Return file "permissions" (normal, executable, or symlink). | |
| 208 | 205 | */ |
| 209 | 206 | int file_perm(const char *zFilename){ |
| 210 | - //TODO(dchest): optimize by calling stat once. | |
| 207 | + /*TODO(dchest): optimize by calling stat once.*/ | |
| 211 | 208 | if( file_isexe(zFilename) ) |
| 212 | - return 1; | |
| 209 | + return PERM_EXE; | |
| 213 | 210 | if( file_islink(zFilename) ) |
| 214 | - return 2; | |
| 215 | - return 0; | |
| 211 | + return PERM_LNK; | |
| 212 | + return PERM_REG; | |
| 216 | 213 | } |
| 217 | 214 | |
| 218 | 215 | /* |
| 219 | 216 | ** Return 1 if zFilename is a directory. Return 0 if zFilename |
| 220 | 217 | ** does not exist. Return 2 if zFilename exists but is something |
| 221 | 218 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -199,22 +199,19 @@ | |
| 199 | #endif |
| 200 | } |
| 201 | |
| 202 | |
| 203 | /* |
| 204 | ** Return file "permissions": |
| 205 | ** 0: normal |
| 206 | ** 1: exec |
| 207 | ** 2: symlink |
| 208 | */ |
| 209 | int file_perm(const char *zFilename){ |
| 210 | //TODO(dchest): optimize by calling stat once. |
| 211 | if( file_isexe(zFilename) ) |
| 212 | return 1; |
| 213 | if( file_islink(zFilename) ) |
| 214 | return 2; |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | ** Return 1 if zFilename is a directory. Return 0 if zFilename |
| 220 | ** does not exist. Return 2 if zFilename exists but is something |
| 221 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -199,22 +199,19 @@ | |
| 199 | #endif |
| 200 | } |
| 201 | |
| 202 | |
| 203 | /* |
| 204 | ** Return file "permissions" (normal, executable, or symlink). |
| 205 | */ |
| 206 | int file_perm(const char *zFilename){ |
| 207 | /*TODO(dchest): optimize by calling stat once.*/ |
| 208 | if( file_isexe(zFilename) ) |
| 209 | return PERM_EXE; |
| 210 | if( file_islink(zFilename) ) |
| 211 | return PERM_LNK; |
| 212 | return PERM_REG; |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | ** Return 1 if zFilename is a directory. Return 0 if zFilename |
| 217 | ** does not exist. Return 2 if zFilename exists but is something |
| 218 |
+10
-3
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -35,10 +35,17 @@ | ||
| 35 | 35 | #define CFTYPE_WIKI 4 |
| 36 | 36 | #define CFTYPE_TICKET 5 |
| 37 | 37 | #define CFTYPE_ATTACHMENT 6 |
| 38 | 38 | #define CFTYPE_EVENT 7 |
| 39 | 39 | |
| 40 | +/* | |
| 41 | +** File permissions used by Fossil internally. | |
| 42 | +*/ | |
| 43 | +#define PERM_REG 0 /* regular file */ | |
| 44 | +#define PERM_EXE 1 /* executable */ | |
| 45 | +#define PERM_LNK 2 /* symlink */ | |
| 46 | + | |
| 40 | 47 | /* |
| 41 | 48 | ** A single F-card within a manifest |
| 42 | 49 | */ |
| 43 | 50 | struct ManifestFile { |
| 44 | 51 | char *zName; /* Name of a file */ |
| @@ -1085,16 +1092,16 @@ | ||
| 1085 | 1092 | /* |
| 1086 | 1093 | ** Compute an appropriate mlink.mperm integer for the permission string |
| 1087 | 1094 | ** of a file. |
| 1088 | 1095 | */ |
| 1089 | 1096 | int manifest_file_mperm(ManifestFile *pFile){ |
| 1090 | - int mperm = 0; | |
| 1097 | + int mperm = PERM_REG; | |
| 1091 | 1098 | if( pFile && pFile->zPerm){ |
| 1092 | 1099 | if( strstr(pFile->zPerm,"x")!=0 ) |
| 1093 | - mperm = 1; | |
| 1100 | + mperm = PERM_EXE; | |
| 1094 | 1101 | else if( strstr(pFile->zPerm,"l")!=0 ) |
| 1095 | - mperm = 2; | |
| 1102 | + mperm = PERM_LNK; | |
| 1096 | 1103 | } |
| 1097 | 1104 | return mperm; |
| 1098 | 1105 | } |
| 1099 | 1106 | |
| 1100 | 1107 | /* |
| 1101 | 1108 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -35,10 +35,17 @@ | |
| 35 | #define CFTYPE_WIKI 4 |
| 36 | #define CFTYPE_TICKET 5 |
| 37 | #define CFTYPE_ATTACHMENT 6 |
| 38 | #define CFTYPE_EVENT 7 |
| 39 | |
| 40 | /* |
| 41 | ** A single F-card within a manifest |
| 42 | */ |
| 43 | struct ManifestFile { |
| 44 | char *zName; /* Name of a file */ |
| @@ -1085,16 +1092,16 @@ | |
| 1085 | /* |
| 1086 | ** Compute an appropriate mlink.mperm integer for the permission string |
| 1087 | ** of a file. |
| 1088 | */ |
| 1089 | int manifest_file_mperm(ManifestFile *pFile){ |
| 1090 | int mperm = 0; |
| 1091 | if( pFile && pFile->zPerm){ |
| 1092 | if( strstr(pFile->zPerm,"x")!=0 ) |
| 1093 | mperm = 1; |
| 1094 | else if( strstr(pFile->zPerm,"l")!=0 ) |
| 1095 | mperm = 2; |
| 1096 | } |
| 1097 | return mperm; |
| 1098 | } |
| 1099 | |
| 1100 | /* |
| 1101 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -35,10 +35,17 @@ | |
| 35 | #define CFTYPE_WIKI 4 |
| 36 | #define CFTYPE_TICKET 5 |
| 37 | #define CFTYPE_ATTACHMENT 6 |
| 38 | #define CFTYPE_EVENT 7 |
| 39 | |
| 40 | /* |
| 41 | ** File permissions used by Fossil internally. |
| 42 | */ |
| 43 | #define PERM_REG 0 /* regular file */ |
| 44 | #define PERM_EXE 1 /* executable */ |
| 45 | #define PERM_LNK 2 /* symlink */ |
| 46 | |
| 47 | /* |
| 48 | ** A single F-card within a manifest |
| 49 | */ |
| 50 | struct ManifestFile { |
| 51 | char *zName; /* Name of a file */ |
| @@ -1085,16 +1092,16 @@ | |
| 1092 | /* |
| 1093 | ** Compute an appropriate mlink.mperm integer for the permission string |
| 1094 | ** of a file. |
| 1095 | */ |
| 1096 | int manifest_file_mperm(ManifestFile *pFile){ |
| 1097 | int mperm = PERM_REG; |
| 1098 | if( pFile && pFile->zPerm){ |
| 1099 | if( strstr(pFile->zPerm,"x")!=0 ) |
| 1100 | mperm = PERM_EXE; |
| 1101 | else if( strstr(pFile->zPerm,"l")!=0 ) |
| 1102 | mperm = PERM_LNK; |
| 1103 | } |
| 1104 | return mperm; |
| 1105 | } |
| 1106 | |
| 1107 | /* |
| 1108 |
+3
-2
| --- src/tar.c | ||
| +++ src/tar.c | ||
| @@ -378,17 +378,18 @@ | ||
| 378 | 378 | * pContent) into header, and set content length to 0 to avoid storing path |
| 379 | 379 | * as file content in the next step. Since 'linkname' header is limited to |
| 380 | 380 | * 100 bytes (-1 byte for terminating zero), if path is greater than that, |
| 381 | 381 | * store symlink as a plain-text file. (Not sure how TAR handles long links.) |
| 382 | 382 | */ |
| 383 | - if( mPerm == 2 && n <= 100 ){ | |
| 383 | + if( mPerm == PERM_LNK && n <= 100 ){ | |
| 384 | 384 | sqlite3_snprintf(100, (char*)&tball.aHdr[157], "%s", blob_str(pContent)); |
| 385 | 385 | cType = '2'; |
| 386 | 386 | n = 0; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - tar_add_header(zName, nName, (mPerm > 0) ? 0755 : 0644, mTime, n, cType); | |
| 389 | + tar_add_header(zName, nName, ( mPerm==PERM_EXE ) ? 0755 : 0644, | |
| 390 | + mTime, n, cType); | |
| 390 | 391 | if( n ){ |
| 391 | 392 | gzip_step(blob_buffer(pContent), n); |
| 392 | 393 | lastPage = n % 512; |
| 393 | 394 | if( lastPage!=0 ){ |
| 394 | 395 | gzip_step(tball.zSpaces, 512 - lastPage); |
| 395 | 396 |
| --- src/tar.c | |
| +++ src/tar.c | |
| @@ -378,17 +378,18 @@ | |
| 378 | * pContent) into header, and set content length to 0 to avoid storing path |
| 379 | * as file content in the next step. Since 'linkname' header is limited to |
| 380 | * 100 bytes (-1 byte for terminating zero), if path is greater than that, |
| 381 | * store symlink as a plain-text file. (Not sure how TAR handles long links.) |
| 382 | */ |
| 383 | if( mPerm == 2 && n <= 100 ){ |
| 384 | sqlite3_snprintf(100, (char*)&tball.aHdr[157], "%s", blob_str(pContent)); |
| 385 | cType = '2'; |
| 386 | n = 0; |
| 387 | } |
| 388 | |
| 389 | tar_add_header(zName, nName, (mPerm > 0) ? 0755 : 0644, mTime, n, cType); |
| 390 | if( n ){ |
| 391 | gzip_step(blob_buffer(pContent), n); |
| 392 | lastPage = n % 512; |
| 393 | if( lastPage!=0 ){ |
| 394 | gzip_step(tball.zSpaces, 512 - lastPage); |
| 395 |
| --- src/tar.c | |
| +++ src/tar.c | |
| @@ -378,17 +378,18 @@ | |
| 378 | * pContent) into header, and set content length to 0 to avoid storing path |
| 379 | * as file content in the next step. Since 'linkname' header is limited to |
| 380 | * 100 bytes (-1 byte for terminating zero), if path is greater than that, |
| 381 | * store symlink as a plain-text file. (Not sure how TAR handles long links.) |
| 382 | */ |
| 383 | if( mPerm == PERM_LNK && n <= 100 ){ |
| 384 | sqlite3_snprintf(100, (char*)&tball.aHdr[157], "%s", blob_str(pContent)); |
| 385 | cType = '2'; |
| 386 | n = 0; |
| 387 | } |
| 388 | |
| 389 | tar_add_header(zName, nName, ( mPerm==PERM_EXE ) ? 0755 : 0644, |
| 390 | mTime, n, cType); |
| 391 | if( n ){ |
| 392 | gzip_step(blob_buffer(pContent), n); |
| 393 | lastPage = n % 512; |
| 394 | if( lastPage!=0 ){ |
| 395 | gzip_step(tball.zSpaces, 512 - lastPage); |
| 396 |
+2
-2
| --- src/update.c | ||
| +++ src/update.c | ||
| @@ -568,12 +568,12 @@ | ||
| 568 | 568 | |
| 569 | 569 | if( pManifest ){ |
| 570 | 570 | pFile = manifest_file_seek(pManifest, file); |
| 571 | 571 | if( pFile ){ |
| 572 | 572 | rid = uuid_to_rid(pFile->zUuid, 0); |
| 573 | - if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==1 ); | |
| 574 | - if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==2 ); | |
| 573 | + if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==PERM_EXE ); | |
| 574 | + if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==PERM_LNK ); | |
| 575 | 575 | manifest_destroy(pManifest); |
| 576 | 576 | return content_get(rid, content); |
| 577 | 577 | } |
| 578 | 578 | manifest_destroy(pManifest); |
| 579 | 579 | if( errCode<=0 ){ |
| 580 | 580 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -568,12 +568,12 @@ | |
| 568 | |
| 569 | if( pManifest ){ |
| 570 | pFile = manifest_file_seek(pManifest, file); |
| 571 | if( pFile ){ |
| 572 | rid = uuid_to_rid(pFile->zUuid, 0); |
| 573 | if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==1 ); |
| 574 | if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==2 ); |
| 575 | manifest_destroy(pManifest); |
| 576 | return content_get(rid, content); |
| 577 | } |
| 578 | manifest_destroy(pManifest); |
| 579 | if( errCode<=0 ){ |
| 580 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -568,12 +568,12 @@ | |
| 568 | |
| 569 | if( pManifest ){ |
| 570 | pFile = manifest_file_seek(pManifest, file); |
| 571 | if( pFile ){ |
| 572 | rid = uuid_to_rid(pFile->zUuid, 0); |
| 573 | if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==PERM_EXE ); |
| 574 | if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==PERM_LNK ); |
| 575 | manifest_destroy(pManifest); |
| 576 | return content_get(rid, content); |
| 577 | } |
| 578 | manifest_destroy(pManifest); |
| 579 | if( errCode<=0 ){ |
| 580 |
+2
-2
| --- src/vfile.c | ||
| +++ src/vfile.c | ||
| @@ -110,14 +110,14 @@ | ||
| 110 | 110 | db_reset(&ridq); |
| 111 | 111 | if( rid==0 || size<0 ){ |
| 112 | 112 | fossil_warning("content missing for %s", pFile->zName); |
| 113 | 113 | continue; |
| 114 | 114 | } |
| 115 | - db_bind_int(&ins, ":isexe", ( manifest_file_mperm(pFile)==1 )); | |
| 115 | + db_bind_int(&ins, ":isexe", ( manifest_file_mperm(pFile)==PERM_EXE )); | |
| 116 | 116 | db_bind_int(&ins, ":id", rid); |
| 117 | 117 | db_bind_text(&ins, ":name", pFile->zName); |
| 118 | - db_bind_int(&ins, ":islink", ( manifest_file_mperm(pFile)==2 )); | |
| 118 | + db_bind_int(&ins, ":islink", ( manifest_file_mperm(pFile)==PERM_LNK )); | |
| 119 | 119 | db_step(&ins); |
| 120 | 120 | db_reset(&ins); |
| 121 | 121 | } |
| 122 | 122 | db_finalize(&ridq); |
| 123 | 123 | db_finalize(&ins); |
| 124 | 124 |
| --- src/vfile.c | |
| +++ src/vfile.c | |
| @@ -110,14 +110,14 @@ | |
| 110 | db_reset(&ridq); |
| 111 | if( rid==0 || size<0 ){ |
| 112 | fossil_warning("content missing for %s", pFile->zName); |
| 113 | continue; |
| 114 | } |
| 115 | db_bind_int(&ins, ":isexe", ( manifest_file_mperm(pFile)==1 )); |
| 116 | db_bind_int(&ins, ":id", rid); |
| 117 | db_bind_text(&ins, ":name", pFile->zName); |
| 118 | db_bind_int(&ins, ":islink", ( manifest_file_mperm(pFile)==2 )); |
| 119 | db_step(&ins); |
| 120 | db_reset(&ins); |
| 121 | } |
| 122 | db_finalize(&ridq); |
| 123 | db_finalize(&ins); |
| 124 |
| --- src/vfile.c | |
| +++ src/vfile.c | |
| @@ -110,14 +110,14 @@ | |
| 110 | db_reset(&ridq); |
| 111 | if( rid==0 || size<0 ){ |
| 112 | fossil_warning("content missing for %s", pFile->zName); |
| 113 | continue; |
| 114 | } |
| 115 | db_bind_int(&ins, ":isexe", ( manifest_file_mperm(pFile)==PERM_EXE )); |
| 116 | db_bind_int(&ins, ":id", rid); |
| 117 | db_bind_text(&ins, ":name", pFile->zName); |
| 118 | db_bind_int(&ins, ":islink", ( manifest_file_mperm(pFile)==PERM_LNK )); |
| 119 | db_step(&ins); |
| 120 | db_reset(&ins); |
| 121 | } |
| 122 | db_finalize(&ridq); |
| 123 | db_finalize(&ins); |
| 124 |
+5
-6
| --- src/zip.c | ||
| +++ src/zip.c | ||
| @@ -139,16 +139,15 @@ | ||
| 139 | 139 | /* Fill in as much of the header as we know. |
| 140 | 140 | */ |
| 141 | 141 | nBlob = pFile ? blob_size(pFile) : 0; |
| 142 | 142 | if( nBlob>0 ){ |
| 143 | 143 | iMethod = 8; |
| 144 | - if( mPerm==1 ) | |
| 145 | - iMode = 0100755; /* executable */ | |
| 146 | - else if( mPerm==2 ) | |
| 147 | - iMode = 0120755; /* symlink */ | |
| 148 | - else | |
| 149 | - iMode = 0100644; /* normal file */ | |
| 144 | + switch( mPerm ){ | |
| 145 | + case PERM_LNK: iMode = 0120755; break; | |
| 146 | + case PERM_EXE: iMode = 0100755; break; | |
| 147 | + default: iMode = 0100644; break; | |
| 148 | + } | |
| 150 | 149 | }else{ |
| 151 | 150 | iMethod = 0; |
| 152 | 151 | iMode = 040755; |
| 153 | 152 | } |
| 154 | 153 | nameLen = strlen(zName); |
| 155 | 154 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -139,16 +139,15 @@ | |
| 139 | /* Fill in as much of the header as we know. |
| 140 | */ |
| 141 | nBlob = pFile ? blob_size(pFile) : 0; |
| 142 | if( nBlob>0 ){ |
| 143 | iMethod = 8; |
| 144 | if( mPerm==1 ) |
| 145 | iMode = 0100755; /* executable */ |
| 146 | else if( mPerm==2 ) |
| 147 | iMode = 0120755; /* symlink */ |
| 148 | else |
| 149 | iMode = 0100644; /* normal file */ |
| 150 | }else{ |
| 151 | iMethod = 0; |
| 152 | iMode = 040755; |
| 153 | } |
| 154 | nameLen = strlen(zName); |
| 155 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -139,16 +139,15 @@ | |
| 139 | /* Fill in as much of the header as we know. |
| 140 | */ |
| 141 | nBlob = pFile ? blob_size(pFile) : 0; |
| 142 | if( nBlob>0 ){ |
| 143 | iMethod = 8; |
| 144 | switch( mPerm ){ |
| 145 | case PERM_LNK: iMode = 0120755; break; |
| 146 | case PERM_EXE: iMode = 0100755; break; |
| 147 | default: iMode = 0100644; break; |
| 148 | } |
| 149 | }else{ |
| 150 | iMethod = 0; |
| 151 | iMode = 040755; |
| 152 | } |
| 153 | nameLen = strlen(zName); |
| 154 |