Skip to content

Commit aabc7cc

Browse files
committed
Add cancellation token checks to datetime property async methods in SystemFile and SystemFolder
1 parent f712149 commit aabc7cc

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

src/System/IO/SystemFile.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,44 +138,68 @@ public virtual Task<Stream> OpenStreamAsync(FileAccess accessMode = FileAccess.R
138138

139139
/// <inheritdoc />
140140
public Task<IStorageProperty<DateTime?>> GetCreatedAtAsync(CancellationToken cancellationToken)
141-
=> Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.CreationTime));
141+
{
142+
cancellationToken.ThrowIfCancellationRequested();
143+
144+
return Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.CreationTime));
145+
}
142146

143147
/// <inheritdoc />
144148
public Task UpdateCreatedAtAsync(DateTime createdDateTime, CancellationToken cancellationToken)
145149
{
150+
cancellationToken.ThrowIfCancellationRequested();
151+
146152
Info.CreationTime = createdDateTime;
147153
return Task.CompletedTask;
148154
}
149155

150156
/// <inheritdoc />
151157
public Task<IStorageProperty<DateTimeOffset?>> GetCreatedAtOffsetAsync(CancellationToken cancellationToken)
152-
=> Task.FromResult<IStorageProperty<DateTimeOffset?>>(new SimpleStorageProperty<DateTimeOffset?>(new DateTimeOffset(Info.CreationTimeUtc, TimeSpan.Zero)));
158+
{
159+
cancellationToken.ThrowIfCancellationRequested();
160+
161+
return Task.FromResult<IStorageProperty<DateTimeOffset?>>(new SimpleStorageProperty<DateTimeOffset?>(new DateTimeOffset(Info.CreationTimeUtc, TimeSpan.Zero)));
162+
}
153163

154164
/// <inheritdoc />
155165
public Task UpdateCreatedAtOffsetAsync(DateTimeOffset createdDateTime, CancellationToken cancellationToken)
156166
{
167+
cancellationToken.ThrowIfCancellationRequested();
168+
157169
Info.CreationTimeUtc = createdDateTime.UtcDateTime;
158170
return Task.CompletedTask;
159171
}
160172

161173
/// <inheritdoc />
162174
public Task<IStorageProperty<DateTime?>> GetLastAccessedAtAsync(CancellationToken cancellationToken)
163-
=> Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.LastAccessTime));
175+
{
176+
cancellationToken.ThrowIfCancellationRequested();
177+
178+
return Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.LastAccessTime));
179+
}
164180

165181
/// <inheritdoc />
166182
public Task UpdateLastAccessedAtAsync(DateTime lastAccessedDateTime, CancellationToken cancellationToken)
167183
{
184+
cancellationToken.ThrowIfCancellationRequested();
185+
168186
Info.LastAccessTime = lastAccessedDateTime;
169187
return Task.CompletedTask;
170188
}
171189

172190
/// <inheritdoc />
173191
public Task<IStorageProperty<DateTime?>> GetLastModifiedAtAsync(CancellationToken cancellationToken)
174-
=> Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.LastWriteTime));
192+
{
193+
cancellationToken.ThrowIfCancellationRequested();
194+
195+
return Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.LastWriteTime));
196+
}
175197

176198
/// <inheritdoc />
177199
public Task UpdateLastModifiedAtAsync(DateTime lastModifiedDateTime, CancellationToken cancellationToken)
178200
{
201+
cancellationToken.ThrowIfCancellationRequested();
202+
179203
Info.LastWriteTime = lastModifiedDateTime;
180204
return Task.CompletedTask;
181205
}

src/System/IO/SystemFolder.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,44 +347,68 @@ public virtual Task<IChildFile> CreateFileAsync(string name, bool overwrite = fa
347347

348348
/// <inheritdoc />
349349
public Task<IStorageProperty<DateTime?>> GetCreatedAtAsync(CancellationToken cancellationToken)
350-
=> Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.CreationTime));
350+
{
351+
cancellationToken.ThrowIfCancellationRequested();
352+
353+
return Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.CreationTime));
354+
}
351355

352356
/// <inheritdoc />
353357
public Task UpdateCreatedAtAsync(DateTime createdDateTime, CancellationToken cancellationToken)
354358
{
359+
cancellationToken.ThrowIfCancellationRequested();
360+
355361
Info.CreationTime = createdDateTime;
356362
return Task.CompletedTask;
357363
}
358364

359365
/// <inheritdoc />
360366
public Task UpdateCreatedAtOffsetAsync(DateTimeOffset createdDateTime, CancellationToken cancellationToken)
361367
{
368+
cancellationToken.ThrowIfCancellationRequested();
369+
362370
Info.CreationTimeUtc = createdDateTime.UtcDateTime;
363371
return Task.CompletedTask;
364372
}
365373

366374
/// <inheritdoc />
367375
public Task<IStorageProperty<DateTimeOffset?>> GetCreatedAtOffsetAsync(CancellationToken cancellationToken)
368-
=> Task.FromResult<IStorageProperty<DateTimeOffset?>>(new SimpleStorageProperty<DateTimeOffset?>(new DateTimeOffset(Info.CreationTimeUtc, TimeSpan.Zero)));
376+
{
377+
cancellationToken.ThrowIfCancellationRequested();
378+
379+
return Task.FromResult<IStorageProperty<DateTimeOffset?>>(new SimpleStorageProperty<DateTimeOffset?>(new DateTimeOffset(Info.CreationTimeUtc, TimeSpan.Zero)));
380+
}
369381

370382
/// <inheritdoc />
371383
public Task<IStorageProperty<DateTime?>> GetLastAccessedAtAsync(CancellationToken cancellationToken)
372-
=> Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.LastAccessTime));
384+
{
385+
cancellationToken.ThrowIfCancellationRequested();
386+
387+
return Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.LastAccessTime));
388+
}
373389

374390
/// <inheritdoc />
375391
public Task UpdateLastAccessedAtAsync(DateTime lastAccessedDateTime, CancellationToken cancellationToken)
376392
{
393+
cancellationToken.ThrowIfCancellationRequested();
394+
377395
Info.LastAccessTime = lastAccessedDateTime;
378396
return Task.CompletedTask;
379397
}
380398

381399
/// <inheritdoc />
382400
public Task<IStorageProperty<DateTime?>> GetLastModifiedAtAsync(CancellationToken cancellationToken)
383-
=> Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.LastWriteTime));
401+
{
402+
cancellationToken.ThrowIfCancellationRequested();
403+
404+
return Task.FromResult<IStorageProperty<DateTime?>>(new SimpleStorageProperty<DateTime?>(Info.LastWriteTime));
405+
}
384406

385407
/// <inheritdoc />
386408
public Task UpdateLastModifiedAtAsync(DateTime lastModifiedDateTime, CancellationToken cancellationToken)
387409
{
410+
cancellationToken.ThrowIfCancellationRequested();
411+
388412
Info.LastWriteTime = lastModifiedDateTime;
389413
return Task.CompletedTask;
390414
}

0 commit comments

Comments
 (0)