function checkForDups(~, fPathNames, names)
% INTERNAL USE ONLY

%   Copyright 2012-2019 The MathWorks, Inc.

%------------------------------------------------------------------------------
%
% function: checkForDups 
%
% inputs:
%    fPathNames
%    names
%
%
%
% abstract:
%
%    This function checks the names for duplicates, and issues an error
%    indicating which files will conflict in a flat hierarchy.
%
%------------------------------------------------------------------------------
    [uniqueNames,idx] = RTW.unique(names);
    
    if (length(uniqueNames) ~= length(names))
        tmp = names(idx);
        dupNames = {};
        for i=1:length(tmp)
            dup = fPathNames(strcmp(names,tmp{i}));
            % if there is only one file with this name, then it is not a dup
            if (length(dup) > 1)
                dupNames = [dupNames dup];  %#ok<AGROW>
            end
        end
        nameList = sprintf('%s\n',dupNames{:});
        DAStudio.error('RTW:buildInfo:duplicateFilesForPackNGo', nameList);
    end
end
