@@ -31,6 +31,7 @@ import {
3131 MonitorId ,
3232 betterPathResolve ,
3333 betterPathIsAbsolute ,
34+ isRunningInTest ,
3435} from '@sofie-package-manager/api'
3536import { BaseWorker } from '../worker'
3637import { GenericWorker } from '../workers/genericWorker/genericWorker'
@@ -111,12 +112,25 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
111112 return this . getFullPath ( this . filePath )
112113 }
113114 static doYouSupportAccess ( worker : BaseWorker , accessor : AccessorOnPackage . Any ) : boolean {
115+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) return false
116+
114117 return defaultDoYouSupportAccess ( worker , accessor )
115118 }
116119 get packageName ( ) : string {
117120 return this . fullPath
118121 }
119122 checkHandleBasic ( ) : AccessorHandlerCheckHandleBasicResult {
123+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) {
124+ return {
125+ success : false ,
126+ knownReason : true ,
127+ reason : {
128+ user : `File share is not supported on this worker` ,
129+ tech : `File share is not supported on ${ process . platform } ` ,
130+ } ,
131+ }
132+ }
133+
120134 if ( this . accessor . type !== Accessor . AccessType . FILE_SHARE ) {
121135 return {
122136 success : false ,
@@ -168,14 +182,46 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
168182 return { success : true }
169183 }
170184 checkCompatibilityWithAccessor ( ) : AccessorHandlerCheckHandleCompatibilityResult {
185+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) {
186+ return {
187+ success : false ,
188+ knownReason : true ,
189+ reason : {
190+ user : `File share is not supported on this worker` ,
191+ tech : `File share is not supported on ${ process . platform } ` ,
192+ } ,
193+ }
194+ }
171195 return { success : true } // no special compatibility checks
172196 }
173197 checkHandleRead ( ) : AccessorHandlerCheckHandleReadResult {
198+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) {
199+ return {
200+ success : false ,
201+ knownReason : true ,
202+ reason : {
203+ user : `File share is not supported on this worker` ,
204+ tech : `File share is not supported on ${ process . platform } ` ,
205+ } ,
206+ }
207+ }
208+
174209 const defaultResult = defaultCheckHandleRead ( this . accessor )
175210 if ( defaultResult ) return defaultResult
176211 return { success : true }
177212 }
178213 checkHandleWrite ( ) : AccessorHandlerCheckHandleWriteResult {
214+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) {
215+ return {
216+ success : false ,
217+ knownReason : true ,
218+ reason : {
219+ user : `File share is not supported on this worker` ,
220+ tech : `File share is not supported on ${ process . platform } ` ,
221+ } ,
222+ }
223+ }
224+
179225 const defaultResult = defaultCheckHandleWrite ( this . accessor )
180226 if ( defaultResult ) return defaultResult
181227 return { success : true }
@@ -199,6 +245,18 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
199245 return { success : true }
200246 }
201247 async tryPackageRead ( ) : Promise < AccessorHandlerTryPackageReadResult > {
248+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) {
249+ return {
250+ success : false ,
251+ knownReason : true ,
252+ reason : {
253+ user : `File share is not supported on this worker` ,
254+ tech : `File share is not supported on ${ process . platform } ` ,
255+ } ,
256+ packageExists : false ,
257+ }
258+ }
259+
202260 try {
203261 // Check if we can open the file for reading:
204262 const fd = await fsOpen ( this . fullPath , 'r' )
@@ -232,6 +290,17 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
232290 return { success : true }
233291 }
234292 private async _checkPackageReadAccess ( ) : Promise < AccessorHandlerCheckPackageReadAccessResult > {
293+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) {
294+ return {
295+ success : false ,
296+ knownReason : true ,
297+ reason : {
298+ user : `File share is not supported on this worker` ,
299+ tech : `File share is not supported on ${ process . platform } ` ,
300+ } ,
301+ }
302+ }
303+
235304 await this . prepareFileAccess ( )
236305
237306 try {
@@ -364,6 +433,17 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
364433 await this . unlinkIfExists ( this . metadataPath )
365434 }
366435 async runCronJob ( packageContainerExp : PackageContainerExpectation ) : Promise < AccessorHandlerRunCronJobResult > {
436+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) {
437+ return {
438+ success : false ,
439+ knownReason : true ,
440+ reason : {
441+ user : `File share is not supported on this worker` ,
442+ tech : `File share is not supported on ${ process . platform } ` ,
443+ } ,
444+ }
445+ }
446+
367447 // Always check read/write access first:
368448 const checkRead = await this . checkPackageContainerReadAccess ( )
369449 if ( ! checkRead . success ) return checkRead
@@ -396,6 +476,17 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
396476 async setupPackageContainerMonitors (
397477 packageContainerExp : PackageContainerExpectation
398478 ) : Promise < SetupPackageContainerMonitorsResult > {
479+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) ) {
480+ return {
481+ success : false ,
482+ knownReason : true ,
483+ reason : {
484+ user : `File share is not supported on this worker` ,
485+ tech : `File share is not supported on ${ process . platform } ` ,
486+ } ,
487+ }
488+ }
489+
399490 const resultingMonitors : Record < MonitorId , MonitorInProgress > = { }
400491 const monitorIds = Object . keys (
401492 packageContainerExp . monitors
@@ -419,6 +510,9 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
419510 operationName : string ,
420511 source : string | GenericAccessorHandle < any >
421512 ) : Promise < PackageOperation > {
513+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) )
514+ throw new Error ( `FileShareAccessor: not supported on ${ process . platform } ` )
515+
422516 await this . fileHandler . clearPackageRemoval ( this . filePath )
423517 return this . logWorkOperation ( operationName , source , this . packageName )
424518 }
@@ -443,6 +537,9 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
443537 * This method should be called prior to any file access being made.
444538 */
445539 async prepareFileAccess ( forceRemount = false ) : Promise < void > {
540+ if ( ! isFileShareSupportedOnCurrentPlatform ( ) )
541+ throw new Error ( `FileShareAccessor: not supported on ${ process . platform } ` )
542+
446543 if ( ! this . originalFolderPath ) throw new Error ( `FileShareAccessor: accessor.folderPath not set!` )
447544 const folderPath = this . originalFolderPath
448545
@@ -680,3 +777,8 @@ export class FileShareAccessorHandle<Metadata> extends GenericFileAccessorHandle
680777interface MappedDriveLetters {
681778 [ driveLetter : string ] : string
682779}
780+
781+ function isFileShareSupportedOnCurrentPlatform ( ) : boolean {
782+ // This is only supported on windows currently
783+ return isRunningInTest ( ) || process . platform === 'win32'
784+ }
0 commit comments