32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
+
+
|
*/
#ifdef _WIN32
# include <direct.h>
# include <windows.h>
# include <sys/utime.h>
#else
# include <sys/time.h>
# include <pwd.h>
# include <grp.h>
#endif
#if INTERFACE
/* Many APIs take an eFType argument which must be one of ExtFILE, RepoFILE,
** or SymFILE.
**
|
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
+
+
+
+
+
+
+
+
+
+
|
/*
** Return TRUE if the named file is an ordinary file. Return false
** for directories, devices, fifos, symlinks, etc.
*/
int file_isfile(const char *zFilename, int eFType){
return getStat(zFilename, eFType) ? 0 : S_ISREG(fx.fileStat.st_mode);
}
/*
** Return TRUE if zFilename is a socket.
*/
int file_issocket(const char *zFilename){
if( getStat(zFilename, ExtFILE) ){
return 0; /* stat() failed. Return false. */
}
return S_ISSOCK(fx.fileStat.st_mode);
}
/*
** Create a symbolic link named zLinkFile that points to zTargetFile.
**
** If allow-symlinks is off, create an ordinary file named zLinkFile
** with the name of zTargetFile as its content.
**/
|
711
712
713
714
715
716
717
718
719
720
721
722
723
724
|
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
iMTime = db_int64(0, "SELECT strftime('%%s',%Q)", g.argv[3]);
zFile = g.argv[2];
file_set_mtime(zFile, iMTime);
iMTime = file_mtime(zFile, RepoFILE);
zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime);
}
/*
** Change access permissions on a file.
*/
void file_set_mode(const char *zFN, int fd, const char *zMode, int bNoErr){
mode_t m;
char *zEnd = 0;
m = strtol(zMode, &zEnd, 0);
if( (zEnd[0] || fchmod(fd, m)) && !bNoErr ){
fossil_fatal("cannot change permissions on %s to \"%s\"",
zFN, zMode);
}
}
/* Change the owner of a file to zOwner. zOwner can be of the form
** USER:GROUP.
*/
void file_set_owner(const char *zFN, int fd, const char *zOwner){
const char *zGrp;
const char *zUsr = zOwner;
struct passwd *pw;
struct group *grp;
uid_t uid = -1;
gid_t gid = -1;
zGrp = strchr(zUsr, ':');
if( zGrp ){
int n = (int)(zGrp - zUsr);
zUsr = fossil_strndup(zUsr, n);
zGrp++;
}
pw = getpwnam(zUsr);
if( pw==0 ){
fossil_fatal("no such user: \"%s\"", zUsr);
}
uid = pw->pw_uid;
if( zGrp ){
grp = getgrnam(zGrp);
if( grp==0 ){
fossil_fatal("no such group: \"%s\"", zGrp);
}
gid = grp->gr_gid;
}
printf("fd=%d zFN=%s uid=%d gid=%d\n", (int)fd, zFN, (int)uid, (int)gid);
if( fchown(fd, uid, gid) ){
fossil_fatal("cannot change ownership of %s to %s",zFN, zOwner);
}
if( zOwner!=zUsr ){
fossil_free((char*)zUsr);
}
}
/*
** Delete a file.
**
** If zFilename is a symbolic link, then it is the link itself that is
** removed, not the object that zFilename points to.
**
|
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
|
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
|
+
|
z = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMtime);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld (%s)", iMtime, z);
fossil_free(z);
fossil_print(" file_mtime(ExtFILE) = %s\n", zBuf);
fossil_print(" file_mode(ExtFILE) = 0%o\n", file_mode(zPath,ExtFILE));
fossil_print(" file_isfile(ExtFILE) = %d\n", file_isfile(zPath,ExtFILE));
fossil_print(" file_isdir(ExtFILE) = %d\n", file_isdir(zPath,ExtFILE));
fossil_print(" file_issocket() = %d\n", file_issocket(zPath));
if( reset ) resetStat();
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_size(zPath,RepoFILE));
fossil_print(" file_size(RepoFILE) = %s\n", zBuf);
iMtime = file_mtime(zPath,RepoFILE);
z = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMtime);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld (%s)", iMtime, z);
fossil_free(z);
|