function updateFileDependency(fileData, relativeWorkerPath)
% Update a file dependency for a parallel pool

% Copyright 2020 The MathWorks, Inc.

% Get the location of the 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

% Only write the file once MATLAB has cleared the name; on Windows, in
% particular, if the file is a mex function, it will be locked in memory
clear(workerFile);

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

end
