98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
** and symlinks are allowed.
** Return false for directories, devices, fifos, etc.
*/
int file_isfile_or_link(const char *zFilename){
#if !defined(_WIN32)
if ( g.allowSymlinks ){
return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode) || S_ISLNK(fileStat.st_mode);
}else{
return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
}
#else
return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
#endif
return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
#endif
}
/*
** Return TRUE if the named file is an ordinary file. Return false
** for directories, devices, fifos, symlinks, etc.
*/
int file_isfile(const char *zFilename){
return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
}
/*
** Return TRUE if the named file is a symlink and symlinks are allowed.
** Return false for all other cases.
**
** On Windows, always return False.
*/
int file_islink(const char *zFilename){
#if !defined(_WIN32)
if( g.allowSymlinks ){
return getStat(zFilename) ? 0 : S_ISLNK(fileStat.st_mode);
}else{
return 0;
}
#else
return 0;
#endif
}
/*
** Create symlink to file on Unix, or plain-text file with
** symlink target if "allow-symlinks" is off or we're on Windows.
**
** Arguments: target file (symlink will point to it), link file
**/
void create_symlink(const char *zTargetFile, const char *zLinkFile){
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
+
-
-
+
+
+
-
-
+
+
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
-
+
+
+
-
+
-
-
+
-
-
-
-
|
blob_set(&content, zTargetFile);
blob_write_to_file(&content, zLinkFile);
blob_reset(&content);
}
}
/*
** Return file permissions (normal, executable, or symlink):
** Return TRUE if the named file is an executable. Return false
** for directories, devices, fifos, symlinks, etc.
** - PERM_EXE if file is executable;
** - PERM_LNK on Unix if file is symlink and allow-symlinks option is on;
** - PERM_REG for all other cases (regular file, directory, fifo, etc).
*/
int file_isexe(const char *zFilename){
if( getStat(zFilename) || !S_ISREG(fileStat.st_mode) ) return 0;
int file_perm(const char *zFilename){
if( getStat(zFilename) ) return PERM_REG;
#if defined(_WIN32)
# if defined(__DMC__) || defined(_MSC_VER)
# define S_IXUSR _S_IEXEC
# endif
return ((S_IXUSR)&fileStat.st_mode)!=0;
if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 )
return PERM_EXE;
else
return PERM_REG;
#else
if( S_ISREG(fileStat.st_mode) &&
return ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0;
((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0 )
return PERM_EXE;
else if( g.allowSymlinks && S_ISLNK(fileStat.st_mode) )
return PERM_LNK;
else
return PERM_REG;
#endif
}
/*
** Return TRUE if the named file is an executable. Return false
** for directories, devices, fifos, symlinks, etc.
*/
int file_isexe(const char *zFilename){
return file_perm(zFilename)==PERM_EXE;
}
/*
** Return TRUE if the named file is a symlink and symlinks are allowed.
** Return file "permissions" (normal, executable, or symlink).
** Return false for all other cases.
**
** On Windows, always return False.
*/
int file_perm(const char *zFilename){
int file_islink(const char *zFilename){
/*TODO(dchest): optimize by calling stat once.*/
if( file_isexe(zFilename) )
return file_perm(zFilename)==PERM_LNK;
return PERM_EXE;
if( file_islink(zFilename) )
return PERM_LNK;
return PERM_REG;
}
/*
** Return 1 if zFilename is a directory. Return 0 if zFilename
** does not exist. Return 2 if zFilename exists but is something
** other than a directory.
*/
|