205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
zName = zBuf;
memcpy(zName, zLinkFile, nName+1);
}
nName = file_simplify_name(zName, nName, 0);
for(i=1; i<nName; i++){
if( zName[i]=='/' ){
zName[i] = 0;
if( file_mkdir(zName, 1) ){
fossil_fatal_recursive("unable to create directory %s", zName);
return;
}
zName[i] = '/';
}
}
#if !defined(_WIN32)
if( symlink(zTargetFile, zName)!=0 )
#else
if( win32_symlink(zTargetFile, zName)!=0 )
#endif
{
fossil_fatal_recursive("unable to create symlink \"%s\"", zName);
}
if( zName!=zBuf ) free(zName);
}else{
Blob content;
blob_set(&content, zTargetFile);
blob_write_to_file(&content, zLinkFile);
blob_reset(&content);
}
}
/*
** Copy symbolic link from zFrom to zTo.
*/
void symlink_copy(const char *zFrom, const char *zTo){
Blob content;
blob_read_link(&content, zFrom);
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
zName = zBuf;
memcpy(zName, zLinkFile, nName+1);
}
nName = file_simplify_name(zName, nName, 0);
for(i=1; i<nName; i++){
if( zName[i]=='/' ){
zName[i] = 0;
#if defined(_WIN32) || defined(__CYGWIN__)
/*
** On Windows, local path looks like: C:/develop/project/file.txt
** The if stops us from trying to create a directory of a drive letter
** C: in this example.
*/
if (!(i == 2 && zName[1] == ':')){
#endif
if( file_mkdir(zName, 1) ){
fossil_fatal_recursive("unable to create directory %s", zName);
return;
}
#if defined(_WIN32) || defined(__CYGWIN__)
}
#endif
zName[i] = '/';
}
}
#if !defined(_WIN32)
if( symlink(zTargetFile, zName)!=0 )
#else
if( win32_symlink(zTargetFile, zName)!=0 )
#endif
{
fossil_fatal_recursive("unable to create symlink \"%s\"", zName);
}
if( zName!=zBuf ) free(zName);
}else{
Blob content;
blob_set(&content, zTargetFile);
blob_write_to_file(&content, zLinkFile);
blob_reset(&content);
}
}
/*
** This code is used in multiple places around fossil. Rather than having
** four or five slightly different cut & paste chunks of code, this function
** does the task of deleting a (possible) link (if necessary) and then
** either creating a link or a file based on input parameters.
** mayNeedDelete is true if we might need to call link_delete, false otherwise.
** needLink is true if we need to create a symlink, false otherwise.
** mayBeLink is true if zName might be a symlink based on the state of the
** checkout and/or file system, false otherwise.
** blob is the binary data to either write as a symlink or as a file.
** zName is the name of the file or symlink to write.
*/
void create_symlink_or_file(int mayNeedDelete, int needLink, int mayBeLink, Blob* blob, const char* zName){
if (mayNeedDelete && (needLink || mayBeLink))
link_delete(zName);
if (needLink)
symlink_create(blob_str(blob), zName);
else
blob_write_to_file(blob, zName);
}
/*
** Copy symbolic link from zFrom to zTo.
*/
void symlink_copy(const char *zFrom, const char *zTo){
Blob content;
blob_read_link(&content, zFrom);
|
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
** Returns zero upon success.
*/
int file_delete(const char *zFilename){
int rc;
#ifdef _WIN32
wchar_t *z = fossil_utf8_to_filename(zFilename);
rc = _wunlink(z);
#else
char *z = fossil_utf8_to_filename(zFilename);
rc = unlink(zFilename);
#endif
fossil_filename_free(z);
return rc;
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
|
** Returns zero upon success.
*/
int file_delete(const char *zFilename){
int rc;
#ifdef _WIN32
wchar_t *z = fossil_utf8_to_filename(zFilename);
rc = _wunlink(z);
#else
char *z = fossil_utf8_to_filename(zFilename);
rc = unlink(zFilename);
#endif
fossil_filename_free(z);
return rc;
}
/*
** Delete a link.
**
** Returns zero upon success.
*/
int link_delete(const char *zFilename){
int rc;
#ifdef _WIN32
wchar_t *z = fossil_utf8_to_filename(zFilename);
rc = win32_unlink_rmdir(z);
#else
char *z = fossil_utf8_to_filename(zFilename);
rc = unlink(zFilename);
#endif
fossil_filename_free(z);
return rc;
}
|