/// <inheritdoc />
        public void SetFileTimestamps(string path, FileTimestamps timestamps, bool followSymlink)
        {
            Contract.Requires(timestamps.CreationTime >= UnixEpoch);
            Contract.Requires(timestamps.AccessTime >= UnixEpoch);
            Contract.Requires(timestamps.LastWriteTime >= UnixEpoch);
            Contract.Requires(timestamps.LastChangeTime >= UnixEpoch);

            var statBuffer = new StatBuffer();

            Timespec creationTime         = Timespec.CreateFromUtcDateTime(timestamps.CreationTime);
            Timespec lastAccessTime       = Timespec.CreateFromUtcDateTime(timestamps.AccessTime);
            Timespec lastModificationTime = Timespec.CreateFromUtcDateTime(timestamps.LastWriteTime);
            Timespec lastStatusChangeTime = Timespec.CreateFromUtcDateTime(timestamps.LastChangeTime);

            statBuffer.TimeCreation     = creationTime.Tv_sec;
            statBuffer.TimeNSecCreation = creationTime.Tv_nsec;

            statBuffer.TimeLastAccess     = lastAccessTime.Tv_sec;
            statBuffer.TimeNSecLastAccess = lastAccessTime.Tv_nsec;

            statBuffer.TimeLastModification     = lastModificationTime.Tv_sec;
            statBuffer.TimeNSecLastModification = lastModificationTime.Tv_nsec;

            statBuffer.TimeLastStatusChange     = lastStatusChangeTime.Tv_sec;
            statBuffer.TimeNSecLastStatusChange = lastStatusChangeTime.Tv_nsec;

            int result = SetTimeStampsForFilePath(path, followSymlink, statBuffer);

            if (result != 0)
            {
                throw new BuildXLException("Failed to open a file to set its timestamps - error: " + Marshal.GetLastWin32Error());
            }
        }
Beispiel #2
0
 /// <summary>
 /// Constructs and starts the cleaner.
 /// </summary>
 /// <param name="folderPath">Path of the folder to periodically cleanup</param>
 /// <param name="minimumFileLifetime">The minimum lifetime of the file to be deleted</param>
 /// <param name="cleanPeriod">How often the cleanup occurs</param>
 /// <param name="timestampToUse">Timestamp to use to determine if the file must be deleted</param>
 public FolderCleaner(string folderPath, TimeSpan minimumFileLifetime, TimeSpan cleanPeriod,
                      FileTimestamps timestampToUse)
 {
     FolderPath          = folderPath;
     MinimumFileLifetime = minimumFileLifetime;
     CleanPeriod         = cleanPeriod;
     CheckTimestamp(timestampToUse);
     TimestampToUse = timestampToUse;
     _cleanLock     = new object();
     _timer         = new Timer(CleanFiles, null, TimeSpan.Zero, cleanPeriod);
 }
Beispiel #3
0
 /// <summary>
 /// Constructs and starts the cleaner.
 /// </summary>
 /// <param name="folderPath">Path of the folder to periodically cleanup</param>
 /// <param name="minimumFileLifetime">The minimum lifetime of the file to be deleted</param>
 /// <param name="cleanPeriod">How often the cleanup occurs</param>
 /// <param name="timestampToUse">Timestamp to use to determine if the file must be deleted</param>
 public FolderCleaner(string folderPath, TimeSpan minimumFileLifetime, TimeSpan cleanPeriod,
     FileTimestamps timestampToUse)
 {
     FolderPath = folderPath;
     MinimumFileLifetime = minimumFileLifetime;
     CleanPeriod = cleanPeriod;
     CheckTimestamp(timestampToUse);
     TimestampToUse = timestampToUse;
     _cleanLock = new object();
     _timer = new Timer(CleanFiles, null, TimeSpan.Zero, cleanPeriod);
 }
Beispiel #4
0
        /// <summary>
        /// Checks if the given timestamp is a valid FileTimestamps enum value.
        /// </summary>
        /// <param name="timestamp">Value to check</param>
        /// <exception cref="InvalidEnumArgumentException">
        /// If an value not present in FileTimestamps enum was given
        /// </exception>
        private void CheckTimestamp(FileTimestamps timestamp)
        {
            switch (timestamp)
            {
            case FileTimestamps.Creation:
            case FileTimestamps.LastAccess:
            case FileTimestamps.LastWrite:
                return;

            default:
                throw new InvalidEnumArgumentException("Unexpected FileTimestamp: \"" + TimestampToUse + "\"");
            }
        }
Beispiel #5
0
        /// <inheritdoc />
        public void SetFileTimestamps(string path, FileTimestamps timestamps, bool followSymlink)
        {
            Contract.Requires(timestamps.CreationTime >= UnixEpoch);
            Contract.Requires(timestamps.AccessTime >= UnixEpoch);
            Contract.Requires(timestamps.LastWriteTime >= UnixEpoch);
            Contract.Requires(timestamps.LastChangeTime >= UnixEpoch);

            unsafe
            {
                Timestamps buffer = new Timestamps();
                buffer.CreationTime     = Timespec.CreateFromUtcDateTime(timestamps.CreationTime);
                buffer.ModificationTime = Timespec.CreateFromUtcDateTime(timestamps.LastWriteTime);
                buffer.AcessTime        = Timespec.CreateFromUtcDateTime(timestamps.AccessTime);
                buffer.ChangeTime       = Timespec.CreateFromUtcDateTime(timestamps.LastChangeTime);

                int result = SetTimeStampsForFilePath(path, followSymlink, &buffer);
                if (result != 0)
                {
                    throw new BuildXLException("Failed to open a file to set its timestamps - error: " + Marshal.GetLastWin32Error());
                }
            }
        }
Beispiel #6
0
 /// <summary>
 /// Checks if the given timestamp is a valid FileTimestamps enum value.
 /// </summary>
 /// <param name="timestamp">Value to check</param>
 /// <exception cref="InvalidEnumArgumentException">
 /// If an value not present in FileTimestamps enum was given
 /// </exception>
 private void CheckTimestamp(FileTimestamps timestamp)
 {
     switch (timestamp)
     {
         case FileTimestamps.Creation:
         case FileTimestamps.LastAccess:
         case FileTimestamps.LastWrite:
             return;
         default:
             throw new InvalidEnumArgumentException("Unexpected FileTimestamp: \"" + TimestampToUse + "\"");
     }
 }