/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
function FileSet(nd,fsUtils){this._contentStack=null;this._contentStackIndex=-1;this._srcStack=null;this._srcStackIndex=-1;this._globOpts=null;this._fileErrorCount=0;this._info=null;this._nd=nd;this._fsUtils=fsUtils};FileSet.prototype.setFiles=function(files,excludes,msgCtx){this._srcStack=files;this._globOpts=addGlobIgnoreOpts(this._globOpts,excludes);this._contentStack=null;this._contentStackIndex=-1;this._srcStackIndex=-1;this._fileErrorCount=0;if(msgCtx){this._info=msgCtx.info}};FileSet.prototype.getFiles=function(){if(this._srcStack){return{files:this._srcStack,exclude:this._globOpts.ignore}}};FileSet.prototype.getFileErrorCount=function(){return this._fileErrorCount};FileSet.prototype.getNextFile=function(){var path,ft,files,i;if(this._contentStack){for(i=this._contentStackIndex+1;i<this._contentStack.length;i++){path=this._contentStack[i];if(!path){continue}this._contentStackIndex=i;ft=this._fsUtils.getFileType(path);if(ft==="f"){if(i+1>=this._contentStack.length){this._contentStack=null;this._contentStackIndex=-1}return path}else if(ft==="?"){this._info("** File '"+path+"' : ignored");this._fileErrorCount++}}}for(i=this._srcStackIndex+1;i<this._srcStack.length;i++){path=this._srcStack[i];this._srcStackIndex++;if(typeof path==="object"){return path}if(!path.startsWith("http")){if(this._globOpts){files=this._nd.glob.sync(path,this._globOpts)}else{files=this._nd.glob.sync(path)}if(this._removeDirs(files)){this._contentStack=files;this._contentStackIndex=-1;return this.getNextFile()}}else{return path}}return null};function addGlobIgnoreOpts(opts,excludes){if(!excludes||excludes.length===0){return opts}if(!opts){opts={}}opts.ignore=excludes;return opts};FileSet.prototype._removeDirs=function(ar){var i,ft,count=0;for(i=0;i<ar.length;i++){ft=this._fsUtils.getFileTypeWithMsg(ar[i]);if(ft==="d"){ar[i]=null;continue}count++}return count};module.exports=FileSet;