This file is indexed.

/usr/include/x86_64-linux-gnu/zypp/PathInfo.h is in libzypp-dev 14.29.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 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
146
147
148
149
150
151
152
153
154
155
156
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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
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
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
/*---------------------------------------------------------------------\
|                          ____ _   __ __ ___                          |
|                         |__  / \ / / . \ . \                         |
|                           / / \ V /|  _/  _/                         |
|                          / /__ | | | | | |                           |
|                         /_____||_| |_| |_|                           |
|                                                                      |
\---------------------------------------------------------------------*/
/** \file zypp/PathInfo.h
 *
*/
#ifndef ZYPP_PATHINFO_H
#define ZYPP_PATHINFO_H

extern "C"
{
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
}

#include <cerrno>
#include <iosfwd>
#include <list>
#include <set>
#include <map>

#include "zypp/Pathname.h"
#include "zypp/CheckSum.h"
#include "zypp/ByteCount.h"

///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////

  class StrMatcher;

  ///////////////////////////////////////////////////////////////////
  /** Types and functions for filesystem operations.
   * \todo move zypp::filesystem stuff into separate header
   * \todo Add tmpfile and tmpdir handling.
   * \todo think about using Exceptions in zypp::filesystem
   * \todo provide a readdir iterator; at least provide an interface
   * using an insert_iterator to be independent from std::container.
  */
  namespace filesystem
  { /////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////
    /** File type information.
     * \todo Think about an \ref g_EnumerationClass
    */
    enum FileType
      {
        FT_NOT_AVAIL = 0x00, // no typeinfo available
        FT_NOT_EXIST = 0x01, // file does not exist
        FT_FILE      = 0x02,
        FT_DIR       = 0x04,
        FT_CHARDEV   = 0x08,
        FT_BLOCKDEV  = 0x10,
        FT_FIFO      = 0x20,
        FT_LINK      = 0x40,
        FT_SOCKET    = 0x80
      };
    ///////////////////////////////////////////////////////////////////

    /** \relates FileType Stram output. */
    extern std::ostream & operator<<( std::ostream & str, FileType obj );

    ///////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////
    //
    //	CLASS NAME : StatMode
    /**
     * @short Wrapper class for mode_t values as derived from ::stat
     **/
    class StatMode
    {
      friend std::ostream & operator<<( std::ostream & str, const StatMode & obj );

    public:
      /** Ctor taking  mode_t value from ::stat. */
      StatMode( const mode_t & mode_r = 0 )
      : _mode( mode_r )
      {}

    public:

      /** \name Query FileType. */
      //@{
      FileType fileType() const;

      bool   isFile()  const { return S_ISREG( _mode ); }
      bool   isDir ()  const { return S_ISDIR( _mode ); }
      bool   isLink()  const { return S_ISLNK( _mode ); }
      bool   isChr()   const { return S_ISCHR( _mode ); }
      bool   isBlk()   const { return S_ISBLK( _mode ); }
      bool   isFifo()  const { return S_ISFIFO( _mode ); }
      bool   isSock()  const { return S_ISSOCK( _mode ); }
      //@}

      /** \name Query user permissions. */
      //@{
      bool   isRUsr()  const { return (_mode & S_IRUSR); }
      bool   isWUsr()  const { return (_mode & S_IWUSR); }
      bool   isXUsr()  const { return (_mode & S_IXUSR); }

      /** Short for isRUsr().*/
      bool   isR()     const { return isRUsr(); }
      /** Short for isWUsr().*/
      bool   isW()     const { return isWUsr(); }
      /** Short for isXUsr().*/
      bool   isX()     const { return isXUsr(); }
      //@}

      /** \name Query group permissions. */
      //@{
      bool   isRGrp()  const { return (_mode & S_IRGRP); }
      bool   isWGrp()  const { return (_mode & S_IWGRP); }
      bool   isXGrp()  const { return (_mode & S_IXGRP); }
      //@}

      /** \name Query others permissions. */
      //@{
      bool   isROth()  const { return (_mode & S_IROTH); }
      bool   isWOth()  const { return (_mode & S_IWOTH); }
      bool   isXOth()  const { return (_mode & S_IXOTH); }
      //@}

      /** \name Query special permissions. */
      //@{
      /** Set UID bit. */
      bool   isUid()   const { return (_mode & S_ISUID); }
      /** Set GID bit. */
      bool   isGid()   const { return (_mode & S_ISGID); }
      /** Sticky bit. */
      bool   isVtx()   const { return (_mode & S_ISVTX); }
      //@}

      /** \name Query permission */
      //@{
      /** Test for equal permission bits. */
      bool   isPerm ( mode_t m ) const { return (m == perm()); }
      /** Test for set permission bits. */
      bool   hasPerm( mode_t m ) const { return (m == (m & perm())); }
      //@}

      /** \name Extract permission bits only. */
      //@{
      mode_t uperm()   const { return (_mode & S_IRWXU); }
      mode_t gperm()   const { return (_mode & S_IRWXG); }
      mode_t operm()   const { return (_mode & S_IRWXO); }
      mode_t perm()    const { return (_mode & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID|S_ISVTX)); }
      //@}

      /** Return the mode_t value. */
      mode_t st_mode() const { return _mode; }

    private:
      mode_t _mode;
    };
    ///////////////////////////////////////////////////////////////////

    /** \relates StatMode Stream output. */
    extern std::ostream & operator<<( std::ostream & str, const StatMode & obj );

    ///////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////
    //
    //	CLASS NAME : DevInoCache
    /** Simple cache remembering device/inode to detect hardlinks.
     * \code
     *     DevInoCache trace;
     *     for ( all files ) {
     *       if ( trace.insert( file.device, file.inode ) ) {
     *         // 1st occurance of file
     *       }
     *         // else: hardlink; already counted this device/inode
     *       }
     *     }
     * \endcode
     **/
    class DevInoCache
    {
    public:
      /** Ctor */
      DevInoCache() {}

      /** Clear cache. */
      void clear() { _devino.clear(); }

      /** Remember dev/ino.
       * \Return <code>true</code> if it's inserted the first
       * time, <code>false</code> if alredy present in cache
       * (a hardlink to a previously remembered file).
       **/
      bool insert( const dev_t & dev_r, const ino_t & ino_r ) {
        return _devino[dev_r].insert( ino_r ).second;
      }

    private:
      std::map<dev_t,std::set<ino_t> > _devino;
    };
    ///////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////
    //
    //	CLASS NAME : PathInfo
    /** Wrapper class for ::stat/::lstat.
     *
     * \note All attribute quieries test for isExist(), and return \c false or
     * \c 0, if stat was not successful.
     *
     * \note For convenience PathInfo is available as zypp::PathInfo too.
     **/
    class PathInfo
    {
      friend std::ostream & operator<<( std::ostream & str, const PathInfo & obj );

    public:
      /** stat() or lstat() */
      enum Mode { STAT, LSTAT };

    public:
      /** \name Construct from Pathname.
       * Default mode is \c STAT.
      */
      //@{
      PathInfo();
      explicit
      PathInfo( const Pathname & path, Mode initial = STAT );
      explicit
      PathInfo( const std::string & path, Mode initial = STAT );
      explicit
      PathInfo( const char * path, Mode initial = STAT );
      //@}

      /**Dtor */
      ~PathInfo();

      /** Return current Pathname. */
      const Pathname &    path()     const { return path_t; }
      /** Return current Pathname as String. */
      const std::string & asString() const { return path_t.asString(); }
      /** Return current Pathname as C-string. */
      const char * c_str()           const { return path_t.asString().c_str(); }
      /** Return current stat Mode. */
      Mode                mode()     const { return mode_e; }
      /** Return error returned from last stat/lstat call. */
      int                 error()    const { return error_i; }

      /** Set a new Pathname. */
      void setPath( const Pathname & path ) { if ( path != path_t ) error_i = -1; path_t = path; }
      /** Set a new Mode . */
      void setMode( Mode mode )             { if ( mode != mode_e ) error_i = -1; mode_e = mode; }

      /** STAT \a path. */
      bool stat      ( const Pathname & path ) { setPath( path ); setMode( STAT );  return operator()(); }
      /** LSTAT \a path. */
      bool lstat     ( const Pathname & path ) { setPath( path ); setMode( LSTAT ); return operator()(); }
      /** Restat \a path using current mode. */
      bool operator()( const Pathname & path ) { setPath( path ); return operator()(); }

      /** STAT current path. */
      bool stat()   { setMode( STAT );  return operator()(); }
      /** LSTAT current path. */
      bool lstat()  { setMode( LSTAT ); return operator()(); }
      /** Restat current path using current mode. */
      bool operator()();

    public:

      /** Return whether valid stat info exists.
       * That's usg. whether the file exist and you had permission to
       * stat it.
      */
      bool   isExist() const { return !error_i; }

      /** \name Query StatMode attibutes.
       * Combines \ref zypp::PathInfo::isExist and \ref zypp::filesystem::StatMode query.
      */
      //@{
      FileType fileType() const;

      bool   isFile()  const { return isExist() && S_ISREG( statbuf_C.st_mode ); }
      bool   isDir ()  const { return isExist() && S_ISDIR( statbuf_C.st_mode ); }
      bool   isLink()  const { return isExist() && S_ISLNK( statbuf_C.st_mode ); }
      bool   isChr()   const { return isExist() && S_ISCHR( statbuf_C.st_mode ); }
      bool   isBlk()   const { return isExist() && S_ISBLK( statbuf_C.st_mode ); }
      bool   isFifo()  const { return isExist() && S_ISFIFO( statbuf_C.st_mode ); }
      bool   isSock()  const { return isExist() && S_ISSOCK( statbuf_C.st_mode ); }

      // permission
      bool   isRUsr()  const { return isExist() && (statbuf_C.st_mode & S_IRUSR); }
      bool   isWUsr()  const { return isExist() && (statbuf_C.st_mode & S_IWUSR); }
      bool   isXUsr()  const { return isExist() && (statbuf_C.st_mode & S_IXUSR); }

      bool   isR()     const { return isRUsr(); }
      bool   isW()     const { return isWUsr(); }
      bool   isX()     const { return isXUsr(); }

      bool   isRGrp()  const { return isExist() && (statbuf_C.st_mode & S_IRGRP); }
      bool   isWGrp()  const { return isExist() && (statbuf_C.st_mode & S_IWGRP); }
      bool   isXGrp()  const { return isExist() && (statbuf_C.st_mode & S_IXGRP); }

      bool   isROth()  const { return isExist() && (statbuf_C.st_mode & S_IROTH); }
      bool   isWOth()  const { return isExist() && (statbuf_C.st_mode & S_IWOTH); }
      bool   isXOth()  const { return isExist() && (statbuf_C.st_mode & S_IXOTH); }

      bool   isUid()   const { return isExist() && (statbuf_C.st_mode & S_ISUID); }
      bool   isGid()   const { return isExist() && (statbuf_C.st_mode & S_ISGID); }
      bool   isVtx()   const { return isExist() && (statbuf_C.st_mode & S_ISVTX); }

      bool   isPerm ( mode_t m ) const { return isExist() && (m == perm()); }
      bool   hasPerm( mode_t m ) const { return isExist() && (m == (m & perm())); }

      mode_t uperm()   const { return isExist() ? (statbuf_C.st_mode & S_IRWXU) : 0; }
      mode_t gperm()   const { return isExist() ? (statbuf_C.st_mode & S_IRWXG) : 0; }
      mode_t operm()   const { return isExist() ? (statbuf_C.st_mode & S_IRWXO) : 0; }
      mode_t perm()    const { return isExist() ? (statbuf_C.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID|S_ISVTX)) : 0; }

      mode_t st_mode() const { return isExist() ? statbuf_C.st_mode : 0; }
      //@}

      /** Return st_mode() as filesystem::StatMode. */
      StatMode asStatMode() const { return st_mode(); }

      nlink_t nlink()  const { return isExist() ? statbuf_C.st_nlink : 0; }

      /** \name Owner and group */
      //@{
      uid_t  owner()   const { return isExist() ? statbuf_C.st_uid : 0; }
      gid_t  group()   const { return isExist() ? statbuf_C.st_gid : 0; }
      //@}

      /** \name Permission according to current uid/gid. */
      //@{
      /** Returns current users permission (<tt>[0-7]</tt>)*/
      mode_t userMay() const;

      bool   userMayR() const { return( userMay() & 04 ); }
      bool   userMayW() const { return( userMay() & 02 ); }
      bool   userMayX() const { return( userMay() & 01 ); }

      bool   userMayRW()  const { return( (userMay() & 06) == 06 ); }
      bool   userMayRX()  const { return( (userMay() & 05) == 05 ); }
      bool   userMayWX()  const { return( (userMay() & 03) == 03 ); }

      bool   userMayRWX() const { return( userMay() == 07 ); }
      //@}

      /** \name Device and inode info. */
      //@{
      ino_t  ino()     const { return isExist() ? statbuf_C.st_ino  : 0; }
      dev_t  dev()     const { return isExist() ? statbuf_C.st_dev  : 0; }
      dev_t  rdev()    const { return isExist() ? statbuf_C.st_rdev : 0; }

      unsigned int major() const;
      unsigned int minor() const;
      //@}

      /** \name Size info. */
      //@{
      off_t         size()    const { return isExist() ? statbuf_C.st_size : 0; }
      unsigned long blksize() const { return isExist() ? statbuf_C.st_blksize : 0; }
      unsigned long blocks()  const { return isExist() ? statbuf_C.st_blocks  : 0; }
      //@}

      /** \name Time stamps. */
      //@{
      time_t atime()   const { return isExist() ? statbuf_C.st_atime : 0; } /* time of last access */
      time_t mtime()   const { return isExist() ? statbuf_C.st_mtime : 0; } /* time of last modification */
      time_t ctime()   const { return isExist() ? statbuf_C.st_ctime : 0; }
      //@}

    private:
      Pathname    path_t;
      struct stat statbuf_C;
      Mode        mode_e;
      int         error_i;
    };
    ///////////////////////////////////////////////////////////////////

    /** \relates PathInfo Stream output. */
    extern std::ostream & operator<<( std::ostream & str, const PathInfo & obj );

    ///////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////
    /** \name Directory related functions. */
    //@{
    /**
     * Like '::mkdir'. Attempt to create a new directory named path. mode
     * specifies the permissions to use. It is modified by the process's
     * umask in the usual way.
     *
     * @return 0 on success, errno on failure
     **/
    int mkdir( const Pathname & path, unsigned mode = 0755 );

    /**
     * Like 'mkdir -p'. No error if directory exists. Make parent directories
     * as needed. mode specifies the permissions to use, if directories have to
     * be created. It is modified by the process's umask in the usual way.
     *
     * @return 0 on success, errno on failure
     **/
    int assert_dir( const Pathname & path, unsigned mode = 0755 );

    /**
     * Like '::rmdir'. Delete a directory, which must be empty.
     *
     * @return 0 on success, errno on failure
     **/
    int rmdir( const Pathname & path );

    /**
     * Like 'rm -r DIR'. Delete a directory, recursively removing its contents.
     *
     * @return 0 on success, ENOTDIR if path is not a directory, otherwise the
     * commands return value.
     **/
    int recursive_rmdir( const Pathname & path );

    /**
     * Like 'rm -r DIR/ *'. Delete directory contents, but keep the directory itself.
     *
     * @return 0 on success, ENOTDIR if path is not a directory, otherwise the
     * commands return value.
     **/
    int clean_dir( const Pathname & path );

    /**
     * Like 'cp -a srcpath destpath'. Copy directory tree. srcpath/destpath must be
     * directories. 'basename srcpath' must not exist in destpath.
     *
     * @return 0 on success, ENOTDIR if srcpath/destpath is not a directory, EEXIST if
     * 'basename srcpath' exists in destpath, otherwise the commands return value.
     **/
    int copy_dir( const Pathname & srcpath, const Pathname & destpath );

    /**
     * Like 'cp -a srcpath/. destpath'. Copy the content of srcpath recursively
     * into destpath. Both \p srcpath and \p destpath has to exists.
     *
     * @return 0 on success, ENOTDIR if srcpath/destpath is not a directory,
     * EEXIST if srcpath and destpath are equal, otherwise the commands
     * return value.
     */
    int copy_dir_content( const Pathname & srcpath, const Pathname & destpath);

    /**
     * Convenience returning <tt>StrMatcher( "[^.]*", Match::GLOB )</tt>
     * \see \ref dirForEach
     */
    const StrMatcher & matchNoDots();

    /**
     * Invoke callback function \a fnc_r for each entry in directory \a dir_r.
     *
     * If \a fnc_r is a \c NULL function \c 0 is returned immediately without even
     * testing or accessing \a dir_r.
     *
     * Otherwise \c ::readdir is used to read the name of every entry in \a dir_r,
     * omitting  \c '.' and \c '..'. \a dir_r and the current entries name are passed
     * as arguments to \a fnc_r. If \a fnc_r returns \c false processing is aborted.
     *
     * @return 0 on success, -1 if aborted by callback, errno > 0 on ::readdir failure.
     */
    int dirForEach( const Pathname & dir_r, function<bool(const Pathname &, const char *const)> fnc_r );

    /**
     * \overload taking a \ref StrMatcher to filter the entries for which \a fnc_r is invoked.
     *
     * For convenience a \ref StrMatcher \ref matchNoDots is provided in this namespace.</tt>
     *
     * \code
     *   bool cbfnc( const Pathname & dir_r, const char *const str_r )
     *   {
     *     D BG <*< " - " << dir_r/str_r << endl;
     *     return true;
     *   }
     *   // Print no-dot files in "/tmp" via callback
     *   filesystem::dirForEach( "/tmp", filesystem::matchNoDots(), cbfnc );
     *
     *   // same via lambda
     *   filesystem::dirForEach( "/tmp", filesystem::matchNoDots(),
     *                           [](const Pathname & dir_r, const std::string & str_r)->bool
     *                           {
     *                             DBG << " - " << dir_r/str_r << endl;
     *                             return true;
     *                           });
     * \endcode
     */
    int dirForEach( const Pathname & dir_r, const StrMatcher & matcher_r, function<bool(const Pathname &, const char *const)> fnc_r );

    /**
     * Return content of directory via retlist. If dots is false
     * entries starting with '.' are not reported. "." and ".."
     * are never reported.
     *
     * Returns just the directory entries as string.
     *
     * @return 0 on success, errno on failure.
     *
     * \todo provide some readdirIterator.
     **/

    int readdir( std::list<std::string> & retlist,
                 const Pathname & path, bool dots = true );

    /**
     * Return content of directory via retlist. If dots is false
     * entries starting with '.' are not reported. "." and ".."
     * are never reported.
     *
     * Returns the directory entries prefixed with \a path.
     *
     * @return 0 on success, errno on failure.
     *
     * \todo provide some readdirIterator.
     **/

    int readdir( std::list<Pathname> & retlist,
                 const Pathname & path, bool dots = true );

    /** Listentry returned by readdir. */
    struct DirEntry {
      std::string name;
      FileType    type;
      DirEntry( const std::string & name_r = std::string(), FileType type_r = FT_NOT_AVAIL )
      : name( name_r )
      , type( type_r )
      {}

      bool operator==( const DirEntry &rhs ) const;
    };

    /** Returned by readdir. */
    typedef std::list<DirEntry> DirContent;

    /**
     * Return content of directory via retlist. If dots is false
     * entries starting with '.' are not reported. "." and ".."
     * are never reported.
     *
     * The type of individual directory entries is determined accoding to
     * statmode (i.e. via stat or lstat).
     *
     * @return 0 on success, errno on failure.
     **/
    int readdir( DirContent & retlist, const Pathname & path,
                 bool dots = true, PathInfo::Mode statmode = PathInfo::STAT );

    /**
     * Check if the specified directory is empty.
     * \param path The path of the directory to check.
     * \return 0 if directory is empty, -1 if not, errno > 0 on failure.
     */
    int is_empty_dir(const Pathname & path);

    //@}

    ///////////////////////////////////////////////////////////////////
    /** \name File related functions. */
    //@{
    /**
     * Create an empty file if it does not yet exist. Make parent directories
     * as needed. mode specifies the permissions to use. It is modified by the
     * process's umask in the usual way.
     *
     * @return 0 on success, errno on failure
     **/
    int assert_file( const Pathname & path, unsigned mode = 0644 );

    /**
     * Change file's modification and access times.
     *
     * \return 0 on success, errno on failure
     * \see man utime
     */
    int touch (const Pathname & path);

    /**
     * Like '::unlink'. Delete a file (symbolic link, socket, fifo or device).
     *
     * @return 0 on success, errno on failure
     **/
    int unlink( const Pathname & path );

    /**
     * Like '::rename'. Renames a file, moving it between directories if required.
     *
     * @return 0 on success, errno on failure
     **/
    int rename( const Pathname & oldpath, const Pathname & newpath );

    /** Exchanges two files or directories.
     *
     * Most common use is when building a new config file (or dir)
     * in a tempfile. After the job is done, configfile and tempfile
     * are exchanged. This includes moving away the configfile in case
     * the tempfile does not exist. Parent directories are created as
     * needed.
     *
     * \note Paths are exchanged using \c ::rename, so take care both paths
     * are located on the same filesystem.
     *
     * \code
     * Pathname configfile( "/etc/myconfig" );
     * TmpFile  newconfig( TmpFile::makeSibling( configfile ) );
     * // now write the new config:
     * std::ofstream o( newconfig.path().c_str() );
     * o << "mew values << endl;
     * o.close();
     * // If everything is fine, exchange the files:
     * exchange( newconfig.path(), configfile );
     * // Now the old configfile is still available at newconfig.path()
     * // until newconfig goes out of scope.
     * \endcode
     *
     * @return 0 on success, errno on failure
     */
    int exchange( const Pathname & lpath, const Pathname & rpath );

    /**
     * Like 'cp file dest'. Copy file to destination file.
     *
     * @return 0 on success, EINVAL if file is not a file, EISDIR if
     * destiantion is a directory, otherwise the commands return value.
     **/
    int copy( const Pathname & file, const Pathname & dest );

    /**
     * Like '::symlink'. Creates a symbolic link named newpath which contains
     * the string oldpath. If newpath exists it will not be overwritten.
     *
     * @return 0 on success, errno on failure.
     **/
    int symlink( const Pathname & oldpath, const Pathname & newpath );

    /**
     * Like '::link'. Creates a hard link named newpath to an existing file
     * oldpath. If newpath exists it will not be overwritten.
     *
     * @return 0 on success, errno on failure.
     **/
    int hardlink( const Pathname & oldpath, const Pathname & newpath );

    /**
     * Create \a newpath as hardlink or copy of \a oldpath.
     *
     * @return 0 on success, errno on failure.
     */
    int hardlinkCopy( const Pathname & oldpath, const Pathname & newpath );

    /**
     * Like '::readlink'. Return the contents of the symbolic link
     * \a symlink_r via \a target_r.
     *
     * @return 0 on success, errno on failure.
     */
    int readlink( const Pathname & symlink_r, Pathname & target_r );
    /** \overload Return an empty Pathname on error. */
    inline Pathname readlink( const Pathname & symlink_r )
    {
      Pathname target;
      readlink( symlink_r, target );
      return target;
    }

    /**
     * Recursively follows the symlink pointed to by \a path_r and returns
     * the Pathname to the real file or directory pointed to by the link.
     *
     * There is a recursion limit of 256 iterations to protect against a cyclic
     * link.
     *
     * @return Pathname of the file or directory pointed to by the given link
     *   if it is a valid link. If \a path_r is not a link, an exact copy of
     *   it is returned. If \a path_r is a broken or a cyclic link, an empty
     *   Pathname is returned and the event logged.
     */
    Pathname expandlink( const Pathname & path_r );

    /**
     * Like 'cp file dest'. Copy file to dest dir.
     *
     * @return 0 on success, EINVAL if file is not a file, ENOTDIR if dest
     * is no directory, otherwise the commands return value.
     **/
    int copy_file2dir( const Pathname & file, const Pathname & dest );
    //@}

    ///////////////////////////////////////////////////////////////////
    /** \name Digest computaion.
     * \todo check cooperation with zypp::Digest
    */
    //@{
    /**
     * Compute a files md5sum.
     *
     * @return the files md5sum on success, otherwise an empty string..
     **/
    std::string md5sum( const Pathname & file );

    /**
     * Compute a files sha1sum.
     *
     * @return the files sha1sum on success, otherwise an empty string..
     **/
    std::string sha1sum( const Pathname & file );
    //@}

    /**
     * Compute a files checksum
     *
     * @return the files checksum on success, otherwise an empty string..
     **/
    std::string checksum( const Pathname & file, const std::string &algorithm );

    /**
     * check files checksum
     *
     * @return true if the checksum matchs
     **/
    bool is_checksum( const Pathname & file, const CheckSum &checksum );

    ///////////////////////////////////////////////////////////////////
    /** \name Changing permissions. */
    //@{
    /**
     * Like '::chmod'. The mode of the file given by path is changed.
     *
     * @return 0 on success, errno on failure
     **/
    int chmod( const Pathname & path, mode_t mode );

    /**
     * Add the \c mode bits to the file given by path.
     *
     * @return 0 on success, errno on failure
     */
    int addmod( const Pathname & path, mode_t mode );

    /**
     * Remove the \c mode bits from the file given by path.
     *
     * @return 0 on success, errno on failure
     */
    int delmod( const Pathname & path, mode_t mode );
    //@}

    ///////////////////////////////////////////////////////////////////
    /** \name Misc. */
    //@{
    /**
     * Test whether a file is compressed (gzip/bzip2).
     *
     * @return ZT_GZ, ZT_BZ2 if file is compressed, otherwise ZT_NONE.
     **/
    enum ZIP_TYPE { ZT_NONE, ZT_GZ, ZT_BZ2 };

    ZIP_TYPE zipType( const Pathname & file );

    /**
     * Erase whatever happens to be located at path (file or directory).
     *
     * @return 0 on success.
     *
     * \todo check cooperation with zypp::TmpFile and zypp::TmpDir
     **/
    int erase( const Pathname & path );

    /**
     * Report free disk space on a mounted file system.
     *
     * path is the path name of any file within the mounted filesystem.
     *
     * @return Free disk space or -1 on error.
     **/
    ByteCount df( const Pathname & path );

    /**
     * Get the current umask (file mode creation mask)
     *
     * @return The current umask
     **/
    mode_t getUmask();

     /**
     * Modify \c mode_r according to the current umask
     * <tt>( mode_r & ~getUmask() )</tt>.
     * \see \ref getUmask.
     * @return The resulting permissions.
     **/
    inline mode_t applyUmaskTo( mode_t mode_r )
    { return mode_r & ~getUmask(); }
    //@}

    /////////////////////////////////////////////////////////////////
  } // namespace filesystem
  ///////////////////////////////////////////////////////////////////

  /** Dragged into namespace zypp. */
  using filesystem::PathInfo;

  /////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
#endif // ZYPP_PATHINFO_H