I have a service that uses
PhysicalFileProvider
to watch files on a windows share. When I run this code on windows it works. When I run it inside a docker container it does not work.
How should I specify the folder path in my appsettings to run on Linux docker container
public class FileWatcher : BackgroundService
{
private readonly string _folderToWatch;
private PhysicalFileProvider _fileProvider;
private IChangeToken _fileChangeToken;
public FileWatcherBase(string folderToWatch)
{
WatchConfig = watchConfig;
_folderToWatch = folderToWatch;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_fileProvider = new PhysicalFileProvider(_folderToWatch);
await Task.Run(FolderWatch, stoppingToken);
}
private void FolderWatch()
{
_fileChangeToken = _fileProvider.Watch($"*.txt");
_fileChangeToken.RegisterChangeCallback(Notify, default);
}
private void Notify(object state)
{
// do something
}
}
Here is the path in the config, this is what is passed into the service "SourceFolder": "\\\\myshare\\files"
The exception I get is :
The path must be absolute. (Parameter 'root') at Microsoft.Extensions.FileProviders.PhysicalFileProvider
If I set the path to be
`"SourceFolder": "/myshare/files"`
I get a
path not found exception