mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 21:39:43 +00:00
files - typed etag()
This commit is contained in:
parent
5fe900dd7b
commit
87d3f3e77b
|
@ -763,12 +763,12 @@ export const FALLBACK_MAX_MEMORY_SIZE_MB = 4096;
|
|||
*/
|
||||
export const ETAG_DISABLED = '';
|
||||
|
||||
export function etag(mtime: number, size: number): string;
|
||||
export function etag(mtime: number | undefined, size: number | undefined): string | undefined;
|
||||
export function etag(mtime: number | undefined, size: number | undefined): string | undefined {
|
||||
if (typeof size !== 'number' || typeof mtime !== 'number') {
|
||||
export function etag(stat: { mtime: number, size: number }): string;
|
||||
export function etag(stat: { mtime: number | undefined, size: number | undefined }): string | undefined;
|
||||
export function etag(stat: { mtime: number | undefined, size: number | undefined }): string | undefined {
|
||||
if (typeof stat.size !== 'number' || typeof stat.mtime !== 'number') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return mtime.toString(29) + size.toString(31);
|
||||
return stat.mtime.toString(29) + stat.size.toString(31);
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ export class FileService extends Disposable implements IFileService {
|
|||
isReadonly: !!(provider.capabilities & FileSystemProviderCapabilities.Readonly),
|
||||
mtime: stat.mtime,
|
||||
size: stat.size,
|
||||
etag: etag(stat.mtime, stat.size)
|
||||
etag: etag({ mtime: stat.mtime, size: stat.size })
|
||||
};
|
||||
|
||||
// check to recurse for directories
|
||||
|
@ -339,7 +339,7 @@ export class FileService extends Disposable implements IFileService {
|
|||
// the file content for comparison which would be much slower to compute.
|
||||
if (
|
||||
options && typeof options.mtime === 'number' && typeof options.etag === 'string' &&
|
||||
options.etag !== ETAG_DISABLED && options.mtime < stat.mtime && options.etag !== etag(options.mtime /* not using stat.mtime for a reason, see above */, stat.size)
|
||||
options.etag !== ETAG_DISABLED && options.mtime < stat.mtime && options.etag !== etag({ mtime: options.mtime /* not using stat.mtime for a reason, see above */, size: stat.size })
|
||||
) {
|
||||
throw new FileOperationError(localize('fileModifiedError', "File Modified Since"), FileOperationResult.FILE_MODIFIED_SINCE, options);
|
||||
}
|
||||
|
|
|
@ -1406,7 +1406,7 @@ suite('Disk File Service', () => {
|
|||
|
||||
let error: FileOperationError | undefined = undefined;
|
||||
try {
|
||||
await service.writeFile(resource, VSBuffer.fromString(newContentLeadingToError), { etag: etag(fakeMtime, fakeSize), mtime: fakeMtime });
|
||||
await service.writeFile(resource, VSBuffer.fromString(newContentLeadingToError), { etag: etag({ mtime: fakeMtime, size: fakeSize }), mtime: fakeMtime });
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
|
@ -1434,7 +1434,7 @@ suite('Disk File Service', () => {
|
|||
|
||||
let error: FileOperationError | undefined = undefined;
|
||||
try {
|
||||
await service.writeFile(resource, VSBuffer.fromString(newContentLeadingToNoError), { etag: etag(fakeMtime, actualSize), mtime: fakeMtime });
|
||||
await service.writeFile(resource, VSBuffer.fromString(newContentLeadingToNoError), { etag: etag({ mtime: fakeMtime, size: actualSize }), mtime: fakeMtime });
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue