1

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

BankMan101
  • 109
  • 9
  • Please explain expected behavior and what exactly "it does not work" means. Error messages? Exceptions? Something that should happen but does not happen...? – Christoph Lütjen Oct 29 '21 at 08:42
  • I am moving the files, when they are placed in the directory. When i run it on windows, it immediately detects the file and moves it as expected. In Linux it never triggers the watch... The issue is the folder its watching and how to specify this so it works on a linux instance – BankMan101 Oct 29 '21 at 08:46
  • Updated with exception – BankMan101 Oct 29 '21 at 09:06
  • You could try "smb//[username]:[password]@\\[IP]\\[Path-to-remote-folder]" - but this is just guessing. – Christoph Lütjen Oct 29 '21 at 10:44

0 Answers0