function addNewFileDependency(clientFile, fileData, relativeWorkerPath)
% Add a new file dependency to a parallel pool

% Copyright 2020 The MathWorks, Inc.

% Get the location for the new file dependency. NB: relativeWorkerPath
% always uses '/' for file separators, which works on all platforms.
workerFile = fullfile(getAttachedFilesFolder(), relativeWorkerPath);

% Ensure that the parent directory exists
parentDir = fileparts(workerFile);
if ~exist(parentDir, 'dir')
    mkdir(parentDir);
end

% Create the new file dependency
fileData.deserializeToFile(workerFile);

% Add the new file dependency to the path
parallel.internal.apishared.AttachedFiles.addAttachedFileToPath(workerFile, clientFile);

end
