Ejemplo n.º 1
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);

            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());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets atime and mtime to current time.
        /// </summary>
        public static int Touch(string pathname, bool followSymlink)
        {
            var timespec = Timespec.CreateFromUtcDateTime(DateTime.UtcNow);
            var buf      = new StatBuffer
            {
                TimeLastAccess           = timespec.Tv_sec,
                TimeNSecLastAccess       = timespec.Tv_nsec,
                TimeLastModification     = timespec.Tv_sec,
                TimeNSecLastModification = timespec.Tv_nsec,
            };

            return(SetTimeStampsForFilePath(pathname, followSymlink, buf));
        }
Ejemplo n.º 3
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());
                }
            }
        }