1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PathInfo.cc
13 #include <sys/types.h> // for ::minor, ::major macros
14 #include <utime.h> // for ::utime
15 #include <sys/statvfs.h>
21 #include "zypp/base/LogTools.h"
22 #include "zypp/base/String.h"
23 #include "zypp/base/IOStream.h"
24 #include "zypp/base/StrMatcher.h"
25 #include "zypp/base/Errno.h"
27 #include "zypp/AutoDispose.h"
28 #include "zypp/ExternalProgram.h"
29 #include "zypp/PathInfo.h"
30 #include "zypp/Digest.h"
31 #include "zypp/TmpPath.h"
36 ///////////////////////////////////////////////////////////////////
38 { /////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////
41 { /////////////////////////////////////////////////////////////////
43 /******************************************************************
45 ** FUNCTION NAME : operator<<
46 ** FUNCTION TYPE : std::ostream &
48 std::ostream & operator<<( std::ostream & str, FileType obj )
51 #define EMUMOUT(T) case T: return str << #T; break
52 EMUMOUT( FT_NOT_AVAIL );
53 EMUMOUT( FT_NOT_EXIST );
56 EMUMOUT( FT_CHARDEV );
57 EMUMOUT( FT_BLOCKDEV );
66 ///////////////////////////////////////////////////////////////////
68 // METHOD NAME : StatMode::fileType
69 // METHOD TYPE : FileType
71 FileType StatMode::fileType() const
91 /******************************************************************
93 ** FUNCTION NAME : operator<<
94 ** FUNCTION TYPE : std::ostream &
96 std::ostream & operator<<( std::ostream & str, const StatMode & obj )
98 iostr::IosFmtFlagsSaver autoResoreState( str );
103 else if ( obj.isDir() )
105 else if ( obj.isLink() )
107 else if ( obj.isChr() )
109 else if ( obj.isBlk() )
111 else if ( obj.isFifo() )
113 else if ( obj.isSock() )
116 str << t << " " << std::setfill( '0' ) << std::setw( 4 ) << std::oct << obj.perm();
120 ///////////////////////////////////////////////////////////////////
124 ///////////////////////////////////////////////////////////////////
126 ///////////////////////////////////////////////////////////////////
128 // METHOD NAME : PathInfo::PathInfo
129 // METHOD TYPE : Constructor
136 ///////////////////////////////////////////////////////////////////
138 // METHOD NAME : PathInfo::PathInfo
139 // METHOD TYPE : Constructor
141 PathInfo::PathInfo( const Pathname & path, Mode initial )
149 ///////////////////////////////////////////////////////////////////
151 // METHOD NAME : PathInfo::PathInfo
152 // METHOD TYPE : Constructor
154 PathInfo::PathInfo( const std::string & path, Mode initial )
162 ///////////////////////////////////////////////////////////////////
164 // METHOD NAME : PathInfo::PathInfo
165 // METHOD TYPE : Constructor
167 PathInfo::PathInfo( const char * path, Mode initial )
175 ///////////////////////////////////////////////////////////////////
177 // METHOD NAME : PathInfo::~PathInfo
178 // METHOD TYPE : Destructor
180 PathInfo::~PathInfo()
184 ///////////////////////////////////////////////////////////////////
186 // METHOD NAME : PathInfo::operator()
187 // METHOD TYPE : bool
189 bool PathInfo::operator()()
191 if ( path_t.empty() ) {
196 error_i = ::stat( path_t.asString().c_str(), &statbuf_C );
199 error_i = ::lstat( path_t.asString().c_str(), &statbuf_C );
208 ///////////////////////////////////////////////////////////////////
210 // METHOD NAME : PathInfo::fileType
211 // METHOD TYPE : File_type
213 FileType PathInfo::fileType() const
216 return asStatMode().fileType();
220 ///////////////////////////////////////////////////////////////////
222 // METHOD NAME : PathInfo::userMay
223 // METHOD TYPE : mode_t
225 mode_t PathInfo::userMay() const
229 if ( owner() == geteuid() ) {
230 return( uperm()/0100 );
231 } else if ( group() == getegid() ) {
232 return( gperm()/010 );
237 /******************************************************************
239 ** FUNCTION NAME : PathInfo::devMajor
240 ** FUNCTION TYPE : unsigned int
242 unsigned int PathInfo::devMajor() const
244 return isBlk() || isChr() ? major(statbuf_C.st_rdev) : 0;
247 /******************************************************************
249 ** FUNCTION NAME : PathInfo::devMinor
250 ** FUNCTION TYPE : unsigned int
252 unsigned int PathInfo::devMinor() const
254 return isBlk() || isChr() ? minor(statbuf_C.st_rdev) : 0;
257 /******************************************************************
259 ** FUNCTION NAME : operator<<
260 ** FUNCTION TYPE : std::ostream &
262 std::ostream & operator<<( std::ostream & str, const PathInfo & obj )
264 iostr::IosFmtFlagsSaver autoResoreState( str );
266 str << obj.asString() << "{";
267 if ( !obj.isExist() ) {
268 str << Errno( obj.error() );
270 str << obj.asStatMode() << " " << std::dec << obj.owner() << "/" << obj.group();
273 str << " size " << obj.size();
279 ///////////////////////////////////////////////////////////////////
281 // filesystem utilities
283 ///////////////////////////////////////////////////////////////////
285 #define logResult MIL << endl, doLogResult
287 /** Helper function to log return values. */
288 inline int doLogResult( const int res, const char * rclass = 0 /*errno*/ )
293 WAR << " FAILED: " << rclass << " " << res << endl;
295 WAR << " FAILED: " << str::strerror( res ) << endl;
301 ///////////////////////////////////////////////////////////////////
303 // METHOD NAME : PathInfo::mkdir
306 int mkdir( const Pathname & path, unsigned mode )
308 MIL << "mkdir " << path << ' ' << str::octstring( mode );
309 if ( ::mkdir( path.asString().c_str(), mode ) == -1 ) {
310 return logResult( errno );
312 return logResult( 0 );
315 ///////////////////////////////////////////////////////////////////
317 // METHOD NAME : assert_dir()
320 int assert_dir( const Pathname & path, unsigned mode )
325 { // Handle existing paths in advance.
333 string spath = path.asString()+"/";
334 string::size_type lastpos = ( path.relative() ? 2 : 1 ); // skip leasding './' or '/'
335 string::size_type pos = string::npos;
338 while ( (pos = spath.find('/',lastpos)) != string::npos )
340 string dir( spath.substr(0,pos) );
341 ret = ::mkdir( dir.c_str(), mode );
344 if ( errno == EEXIST ) // ignore errors about already existing paths
349 WAR << " FAILED: mkdir " << dir << ' ' << str::octstring( mode ) << " errno " << ret << endl;
354 MIL << "mkdir " << dir << ' ' << str::octstring( mode ) << endl;
362 ///////////////////////////////////////////////////////////////////
364 // METHOD NAME : rmdir
367 int rmdir( const Pathname & path )
369 MIL << "rmdir " << path;
370 if ( ::rmdir( path.asString().c_str() ) == -1 ) {
371 return logResult( errno );
373 return logResult( 0 );
376 ///////////////////////////////////////////////////////////////////
378 // METHOD NAME : recursive_rmdir
381 static int recursive_rmdir_1( const Pathname & dir, bool removeDir = true )
386 if ( ! (dp = opendir( dir.c_str() )) )
387 return logResult( errno );
389 while ( (d = readdir(dp)) )
391 std::string direntry = d->d_name;
392 if ( direntry == "." || direntry == ".." )
394 Pathname new_path( dir / d->d_name );
397 if ( ! lstat( new_path.c_str(), &st ) )
399 if ( S_ISDIR( st.st_mode ) )
400 recursive_rmdir_1( new_path );
402 ::unlink( new_path.c_str() );
407 if ( removeDir && ::rmdir( dir.c_str() ) < 0 )
412 ///////////////////////////////////////////////////////////////////
413 int recursive_rmdir( const Pathname & path )
415 MIL << "recursive_rmdir " << path << ' ';
418 if ( !p.isExist() ) {
419 return logResult( 0 );
423 return logResult( ENOTDIR );
426 return logResult( recursive_rmdir_1( path ) );
429 ///////////////////////////////////////////////////////////////////
431 // METHOD NAME : clean_dir
434 int clean_dir( const Pathname & path )
436 MIL << "clean_dir " << path << ' ';
439 if ( !p.isExist() ) {
440 return logResult( 0 );
444 return logResult( ENOTDIR );
447 return logResult( recursive_rmdir_1( path, false/* don't remove path itself */ ) );
450 ///////////////////////////////////////////////////////////////////
452 // METHOD NAME : copy_dir
455 int copy_dir( const Pathname & srcpath, const Pathname & destpath )
457 MIL << "copy_dir " << srcpath << " -> " << destpath << ' ';
459 PathInfo sp( srcpath );
461 return logResult( ENOTDIR );
464 PathInfo dp( destpath );
466 return logResult( ENOTDIR );
469 PathInfo tp( destpath + srcpath.basename() );
470 if ( tp.isExist() ) {
471 return logResult( EEXIST );
475 const char *const argv[] = {
479 srcpath.asString().c_str(),
480 destpath.asString().c_str(),
483 ExternalProgram prog( argv, ExternalProgram::Stderr_To_Stdout );
484 for ( string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
485 MIL << " " << output;
487 int ret = prog.close();
488 return logResult( ret, "returned" );
491 ///////////////////////////////////////////////////////////////////
493 // METHOD NAME : copy_dir_content
496 int copy_dir_content(const Pathname & srcpath, const Pathname & destpath)
498 MIL << "copy_dir " << srcpath << " -> " << destpath << ' ';
500 PathInfo sp( srcpath );
502 return logResult( ENOTDIR );
505 PathInfo dp( destpath );
507 return logResult( ENOTDIR );
510 if ( srcpath == destpath ) {
511 return logResult( EEXIST );
514 std::string src( srcpath.asString());
516 const char *const argv[] = {
521 destpath.asString().c_str(),
524 ExternalProgram prog( argv, ExternalProgram::Stderr_To_Stdout );
525 for ( string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
526 MIL << " " << output;
528 int ret = prog.close();
529 return logResult( ret, "returned" );
532 ///////////////////////////////////////////////////////////////////////
534 ///////////////////////////////////////////////////////////////////////
536 const StrMatcher & matchNoDots()
538 static StrMatcher noDots( "[^.]*", Match::GLOB );
542 int dirForEach( const Pathname & dir_r, function<bool(const Pathname &, const char *const)> fnc_r )
547 AutoDispose<DIR *> dir( ::opendir( dir_r.c_str() ),
548 []( DIR * dir_r ) { if ( dir_r ) ::closedir( dir_r ); } );
550 MIL << "readdir " << dir_r << ' ';
552 return logResult( errno );
553 MIL << endl; // close line before callbacks are invoked.
556 for ( struct dirent * entry = ::readdir( dir ); entry; entry = ::readdir( dir ) )
558 if ( entry->d_name[0] == '.' && ( entry->d_name[1] == '\0' || ( entry->d_name[1] == '.' && entry->d_name[2] == '\0' ) ) )
559 continue; // omitt . and ..
561 if ( ! fnc_r( dir_r, entry->d_name ) )
570 int dirForEach( const Pathname & dir_r, const StrMatcher & matcher_r, function<bool( const Pathname &, const char *const)> fnc_r )
575 bool nodots = ( &matcher_r == &matchNoDots() );
576 return dirForEach( dir_r,
577 [&]( const Pathname & dir_r, const char *const name_r )->bool
579 if ( ( nodots && name_r[0] == '.' ) || ! matcher_r( name_r ) )
581 return fnc_r( dir_r, name_r );
585 ///////////////////////////////////////////////////////////////////
587 ///////////////////////////////////////////////////////////////////
589 int readdir( std::list<std::string> & retlist_r, const Pathname & path_r, bool dots_r )
592 return dirForEach( path_r,
593 [&]( const Pathname & dir_r, const char *const name_r )->bool
595 if ( dots_r || name_r[0] != '.' )
596 retlist_r.push_back( name_r );
602 int readdir( std::list<Pathname> & retlist_r, const Pathname & path_r, bool dots_r )
605 return dirForEach( path_r,
606 [&]( const Pathname & dir_r, const char *const name_r )->bool
608 if ( dots_r || name_r[0] != '.' )
609 retlist_r.push_back( dir_r/name_r );
614 bool DirEntry::operator==( const DirEntry &rhs ) const
616 // if one of the types is not known, use the name only
617 if ( type == FT_NOT_AVAIL || rhs.type == FT_NOT_AVAIL )
618 return ( name == rhs.name );
619 return ((name == rhs.name ) && (type == rhs.type));
622 int readdir( DirContent & retlist_r, const Pathname & path_r, bool dots_r, PathInfo::Mode statmode_r )
625 return dirForEach( path_r,
626 [&]( const Pathname & dir_r, const char *const name_r )->bool
628 if ( dots_r || name_r[0] != '.' )
629 retlist_r.push_back( DirEntry( name_r, PathInfo( dir_r/name_r, statmode_r ).fileType() ) );
634 std::ostream & operator<<( std::ostream & str, const DirContent & obj )
635 { return dumpRange( str, obj.begin(), obj.end() ); }
637 ///////////////////////////////////////////////////////////////////
639 ///////////////////////////////////////////////////////////////////
641 int is_empty_dir( const Pathname & path_r )
643 return dirForEach( path_r,
644 [&]( const Pathname & dir_r, const char *const name_r )->bool
648 ///////////////////////////////////////////////////////////////////
650 // METHOD NAME : unlink
653 int unlink( const Pathname & path )
655 MIL << "unlink " << path;
656 if ( ::unlink( path.asString().c_str() ) == -1 ) {
657 return logResult( errno );
659 return logResult( 0 );
662 ///////////////////////////////////////////////////////////////////
664 // METHOD NAME : rename
667 int rename( const Pathname & oldpath, const Pathname & newpath )
669 MIL << "rename " << oldpath << " -> " << newpath;
670 if ( ::rename( oldpath.asString().c_str(), newpath.asString().c_str() ) == -1 ) {
671 return logResult( errno );
673 return logResult( 0 );
676 ///////////////////////////////////////////////////////////////////
678 // METHOD NAME : exchange
681 int exchange( const Pathname & lpath, const Pathname & rpath )
683 MIL << "exchange " << lpath << " <-> " << rpath;
684 if ( lpath.empty() || rpath.empty() )
685 return logResult( EINVAL );
687 PathInfo linfo( lpath );
688 PathInfo rinfo( rpath );
690 if ( ! linfo.isExist() )
692 if ( ! rinfo.isExist() )
693 return logResult( 0 ); // both don't exist.
695 // just rename rpath -> lpath
696 int ret = assert_dir( lpath.dirname() );
698 return logResult( ret );
699 if ( ::rename( rpath.c_str(), lpath.c_str() ) == -1 ) {
700 return logResult( errno );
702 return logResult( 0 );
705 // HERE: lpath exists:
706 if ( ! rinfo.isExist() )
708 // just rename lpath -> rpath
709 int ret = assert_dir( rpath.dirname() );
711 return logResult( ret );
712 if ( ::rename( lpath.c_str(), rpath.c_str() ) == -1 ) {
713 return logResult( errno );
715 return logResult( 0 );
719 TmpFile tmpfile( TmpFile::makeSibling( rpath ) );
721 return logResult( errno );
722 Pathname tmp( tmpfile.path() );
723 ::unlink( tmp.c_str() );
725 if ( ::rename( lpath.c_str(), tmp.c_str() ) == -1 ) {
726 return logResult( errno );
728 if ( ::rename( rpath.c_str(), lpath.c_str() ) == -1 ) {
729 ::rename( tmp.c_str(), lpath.c_str() );
730 return logResult( errno );
732 if ( ::rename( tmp.c_str(), rpath.c_str() ) == -1 ) {
733 ::rename( lpath.c_str(), rpath.c_str() );
734 ::rename( tmp.c_str(), lpath.c_str() );
735 return logResult( errno );
737 return logResult( 0 );
740 ///////////////////////////////////////////////////////////////////
742 // METHOD NAME : copy
745 int copy( const Pathname & file, const Pathname & dest )
747 MIL << "copy " << file << " -> " << dest << ' ';
750 if ( !sp.isFile() ) {
751 return logResult( EINVAL );
756 return logResult( EISDIR );
759 const char *const argv[] = {
761 "--remove-destination",
763 file.asString().c_str(),
764 dest.asString().c_str(),
767 ExternalProgram prog( argv, ExternalProgram::Stderr_To_Stdout );
768 for ( string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
769 MIL << " " << output;
771 int ret = prog.close();
772 return logResult( ret, "returned" );
775 ///////////////////////////////////////////////////////////////////
777 // METHOD NAME : symlink
780 int symlink( const Pathname & oldpath, const Pathname & newpath )
782 MIL << "symlink " << newpath << " -> " << oldpath;
783 if ( ::symlink( oldpath.asString().c_str(), newpath.asString().c_str() ) == -1 ) {
784 return logResult( errno );
786 return logResult( 0 );
789 ///////////////////////////////////////////////////////////////////
791 // METHOD NAME : hardlink
794 int hardlink( const Pathname & oldpath, const Pathname & newpath )
796 MIL << "hardlink " << newpath << " -> " << oldpath;
797 if ( ::link( oldpath.asString().c_str(), newpath.asString().c_str() ) == -1 ) {
798 return logResult( errno );
800 return logResult( 0 );
803 ///////////////////////////////////////////////////////////////////
805 // METHOD NAME : hardlink
808 int hardlinkCopy( const Pathname & oldpath, const Pathname & newpath )
810 MIL << "hardlinkCopy " << oldpath << " -> " << newpath;
812 PathInfo pi( oldpath, PathInfo::LSTAT );
815 // dont hardlink symlinks!
816 return copy( oldpath, newpath );
822 int res = unlink( newpath );
824 return logResult( res );
827 // Here: no symlink, no newpath
828 if ( ::link( oldpath.asString().c_str(), newpath.asString().c_str() ) == -1 )
832 case EPERM: // /proc/sys/fs/protected_hardlink in proc(5)
833 case EXDEV: // oldpath and newpath are not on the same mounted file system
834 return copy( oldpath, newpath );
837 return logResult( errno );
839 return logResult( 0 );
842 ///////////////////////////////////////////////////////////////////
844 // METHOD NAME : readlink
847 int readlink( const Pathname & symlink_r, Pathname & target_r )
849 static const ssize_t bufsiz = 2047;
850 static char buf[bufsiz+1];
851 ssize_t ret = ::readlink( symlink_r.c_str(), buf, bufsiz );
854 target_r = Pathname();
855 MIL << "readlink " << symlink_r;
856 return logResult( errno );
863 ///////////////////////////////////////////////////////////////////
865 // METHOD NAME : expandlink
866 // METHOD TYPE : Pathname
868 Pathname expandlink( const Pathname & path_r )
870 static const unsigned int level_limit = 256;
871 static unsigned int count;
872 Pathname path(path_r);
873 PathInfo info(path_r, PathInfo::LSTAT);
875 for (count = level_limit; info.isLink() && count; count--)
877 DBG << "following symlink " << path;
878 path = path.dirname() / readlink(path);
879 DBG << "->" << path << std::endl;
880 info = PathInfo(path, PathInfo::LSTAT);
883 // expand limit reached
886 ERR << "Expand level limit reached. Probably a cyclic symbolic link." << endl;
890 else if (count < level_limit)
892 // check for a broken link
893 if (PathInfo(path).isExist())
895 // broken link, return an empty path
898 ERR << path << " is broken (expanded from " << path_r << ")" << endl;
903 // not a symlink, return the original pathname
904 DBG << "not a symlink" << endl;
908 ///////////////////////////////////////////////////////////////////
910 // METHOD NAME : copy_file2dir
913 int copy_file2dir( const Pathname & file, const Pathname & dest )
915 MIL << "copy_file2dir " << file << " -> " << dest << ' ';
918 if ( !sp.isFile() ) {
919 return logResult( EINVAL );
924 return logResult( ENOTDIR );
927 const char *const argv[] = {
930 file.asString().c_str(),
931 dest.asString().c_str(),
934 ExternalProgram prog( argv, ExternalProgram::Stderr_To_Stdout );
935 for ( string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
936 MIL << " " << output;
938 int ret = prog.close();
939 return logResult( ret, "returned" );
942 ///////////////////////////////////////////////////////////////////
944 // METHOD NAME : md5sum
945 // METHOD TYPE : std::string
947 std::string md5sum( const Pathname & file )
949 if ( ! PathInfo( file ).isFile() ) {
952 std::ifstream istr( file.asString().c_str() );
956 return Digest::digest( "MD5", istr );
959 ///////////////////////////////////////////////////////////////////
961 // METHOD NAME : sha1sum
962 // METHOD TYPE : std::string
964 std::string sha1sum( const Pathname & file )
966 return checksum(file, "SHA1");
969 ///////////////////////////////////////////////////////////////////
971 // METHOD NAME : checksum
972 // METHOD TYPE : std::string
974 std::string checksum( const Pathname & file, const std::string &algorithm )
976 if ( ! PathInfo( file ).isFile() ) {
979 std::ifstream istr( file.asString().c_str() );
983 return Digest::digest( algorithm, istr );
986 bool is_checksum( const Pathname & file, const CheckSum &checksum )
988 return ( filesystem::checksum(file, checksum.type()) == checksum.checksum() );
991 ///////////////////////////////////////////////////////////////////
993 // METHOD NAME : erase
996 int erase( const Pathname & path )
999 PathInfo p( path, PathInfo::LSTAT );
1003 res = recursive_rmdir( path );
1005 res = unlink( path );
1010 ///////////////////////////////////////////////////////////////////
1012 // METHOD NAME : chmod
1013 // METHOD TYPE : int
1015 int chmod( const Pathname & path, mode_t mode )
1017 MIL << "chmod " << path << ' ' << str::octstring( mode );
1018 if ( ::chmod( path.asString().c_str(), mode ) == -1 ) {
1019 return logResult( errno );
1021 return logResult( 0 );
1024 int addmod( const Pathname & path, mode_t mode )
1026 mode_t omode( PathInfo( path ).st_mode() );
1027 mode_t tmode( omode | mode );
1028 if ( omode != mode )
1029 return chmod( path, tmode );
1033 int delmod( const Pathname & path, mode_t mode )
1035 mode_t omode( PathInfo( path ).st_mode() );
1036 mode_t tmode( omode & ~mode );
1037 if ( omode != mode )
1038 return chmod( path, tmode );
1042 //////////////////////////////////////////////////////////////////
1044 // METHOD NAME : zipType
1045 // METHOD TYPE : ZIP_TYPE
1047 ZIP_TYPE zipType( const Pathname & file )
1049 ZIP_TYPE ret = ZT_NONE;
1051 int fd = open( file.asString().c_str(), O_RDONLY|O_CLOEXEC );
1054 const int magicSize = 3;
1055 unsigned char magic[magicSize];
1056 memset( magic, 0, magicSize );
1057 if ( read( fd, magic, magicSize ) == magicSize ) {
1058 if ( magic[0] == 0037 && magic[1] == 0213 ) {
1060 } else if ( magic[0] == 'B' && magic[1] == 'Z' && magic[2] == 'h' ) {
1070 ///////////////////////////////////////////////////////////////////
1073 // METHOD TYPE : ByteCount
1075 ByteCount df( const Pathname & path_r )
1077 ByteCount ret( -1 );
1079 if ( statvfs( path_r.c_str(), &sb ) == 0 )
1081 ret = sb.f_bfree * sb.f_bsize;
1086 ///////////////////////////////////////////////////////////////////
1088 // METHOD NAME : getUmask
1089 // METHOD TYPE : mode_t
1093 mode_t mask = ::umask( 0022 );
1098 ///////////////////////////////////////////////////////////////////
1100 // METHOD NAME : getUmask
1101 // METHOD TYPE : mode_t
1103 int assert_file( const Pathname & path, unsigned mode )
1105 int ret = assert_dir( path.dirname() );
1106 MIL << "assert_file " << str::octstring( mode ) << " " << path;
1108 return logResult( ret );
1110 PathInfo pi( path );
1112 return logResult( pi.isFile() ? 0 : EEXIST );
1114 int fd = ::creat( path.c_str(), mode );
1116 return logResult( errno );
1119 return logResult( 0 );
1122 ///////////////////////////////////////////////////////////////////
1124 // METHOD NAME : touch
1125 // METHOD TYPE : int
1127 int touch (const Pathname & path)
1129 MIL << "touch " << path;
1130 struct ::utimbuf times;
1131 times.actime = ::time( 0 );
1132 times.modtime = ::time( 0 );
1133 if ( ::utime( path.asString().c_str(), × ) == -1 ) {
1134 return logResult( errno );
1136 return logResult( 0 );
1139 /////////////////////////////////////////////////////////////////
1140 } // namespace filesystem
1141 ///////////////////////////////////////////////////////////////////
1142 /////////////////////////////////////////////////////////////////
1144 ///////////////////////////////////////////////////////////////////