Fossil SCM

Introduce constants for internal permissions (executable/symlink).

dmitry 2011-08-25 11:42 symlinks
Commit f6daee3e7be36e7b435b116941ae3d9c68e6dabe
+5 -6
--- src/export.c
+++ src/export.c
@@ -271,16 +271,15 @@
271271
int mPerm = db_column_int(&q4,2);
272272
if( zNew==0)
273273
printf("D %s\n", zName);
274274
else if( bag_find(&blobs, zNew) ) {
275275
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
+ }
282281
printf("M %s :%d %s\n", zPerm, BLOBMARK(zNew), zName);
283282
}
284283
}
285284
db_finalize(&q4);
286285
db_finalize(&q3);
287286
--- 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 @@
199199
#endif
200200
}
201201
202202
203203
/*
204
-** Return file "permissions":
205
-** 0: normal
206
-** 1: exec
207
-** 2: symlink
204
+** Return file "permissions" (normal, executable, or symlink).
208205
*/
209206
int file_perm(const char *zFilename){
210
- //TODO(dchest): optimize by calling stat once.
207
+ /*TODO(dchest): optimize by calling stat once.*/
211208
if( file_isexe(zFilename) )
212
- return 1;
209
+ return PERM_EXE;
213210
if( file_islink(zFilename) )
214
- return 2;
215
- return 0;
211
+ return PERM_LNK;
212
+ return PERM_REG;
216213
}
217214
218215
/*
219216
** Return 1 if zFilename is a directory. Return 0 if zFilename
220217
** does not exist. Return 2 if zFilename exists but is something
221218
--- 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 @@
3535
#define CFTYPE_WIKI 4
3636
#define CFTYPE_TICKET 5
3737
#define CFTYPE_ATTACHMENT 6
3838
#define CFTYPE_EVENT 7
3939
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
+
4047
/*
4148
** A single F-card within a manifest
4249
*/
4350
struct ManifestFile {
4451
char *zName; /* Name of a file */
@@ -1085,16 +1092,16 @@
10851092
/*
10861093
** Compute an appropriate mlink.mperm integer for the permission string
10871094
** of a file.
10881095
*/
10891096
int manifest_file_mperm(ManifestFile *pFile){
1090
- int mperm = 0;
1097
+ int mperm = PERM_REG;
10911098
if( pFile && pFile->zPerm){
10921099
if( strstr(pFile->zPerm,"x")!=0 )
1093
- mperm = 1;
1100
+ mperm = PERM_EXE;
10941101
else if( strstr(pFile->zPerm,"l")!=0 )
1095
- mperm = 2;
1102
+ mperm = PERM_LNK;
10961103
}
10971104
return mperm;
10981105
}
10991106
11001107
/*
11011108
--- 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 @@
378378
* pContent) into header, and set content length to 0 to avoid storing path
379379
* as file content in the next step. Since 'linkname' header is limited to
380380
* 100 bytes (-1 byte for terminating zero), if path is greater than that,
381381
* store symlink as a plain-text file. (Not sure how TAR handles long links.)
382382
*/
383
- if( mPerm == 2 && n <= 100 ){
383
+ if( mPerm == PERM_LNK && n <= 100 ){
384384
sqlite3_snprintf(100, (char*)&tball.aHdr[157], "%s", blob_str(pContent));
385385
cType = '2';
386386
n = 0;
387387
}
388388
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);
390391
if( n ){
391392
gzip_step(blob_buffer(pContent), n);
392393
lastPage = n % 512;
393394
if( lastPage!=0 ){
394395
gzip_step(tball.zSpaces, 512 - lastPage);
395396
--- 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 @@
568568
569569
if( pManifest ){
570570
pFile = manifest_file_seek(pManifest, file);
571571
if( pFile ){
572572
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 );
575575
manifest_destroy(pManifest);
576576
return content_get(rid, content);
577577
}
578578
manifest_destroy(pManifest);
579579
if( errCode<=0 ){
580580
--- 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 @@
110110
db_reset(&ridq);
111111
if( rid==0 || size<0 ){
112112
fossil_warning("content missing for %s", pFile->zName);
113113
continue;
114114
}
115
- db_bind_int(&ins, ":isexe", ( manifest_file_mperm(pFile)==1 ));
115
+ db_bind_int(&ins, ":isexe", ( manifest_file_mperm(pFile)==PERM_EXE ));
116116
db_bind_int(&ins, ":id", rid);
117117
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 ));
119119
db_step(&ins);
120120
db_reset(&ins);
121121
}
122122
db_finalize(&ridq);
123123
db_finalize(&ins);
124124
--- 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 @@
139139
/* Fill in as much of the header as we know.
140140
*/
141141
nBlob = pFile ? blob_size(pFile) : 0;
142142
if( nBlob>0 ){
143143
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
+ }
150149
}else{
151150
iMethod = 0;
152151
iMode = 040755;
153152
}
154153
nameLen = strlen(zName);
155154
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button