public String createSubdir ( ) throws IOException { if ( ! saveData ) return "" ; File dr = new File ( dataRoot ) ; dr . mkdirs ( ) ; File [ ] rootChildren = dr . listFiles ( ) ; int i = 1 ; while ( childrenExist ( rootChildren , i + "" ) ) i ++ ; File f = new File ( dataRoot + "/" + i ) ; f . mkdirs ( ) ; currentDir = f . getAbsolutePath ( ) ; log . info ( "Created training data directory: " + currentDir ) ; File mov = new File ( getVideoDir ( ) ) ; mov . mkdirs ( ) ; File model = new File ( getModelDir ( ) ) ; model . mkdirs ( ) ; File stat = new File ( getStat ( ) ) ; File info = new File ( getInfo ( ) ) ; stat . createNewFile ( ) ; info . createNewFile ( ) ; return f . getAbsolutePath ( ) ; }
FIXME race condition if you create them at the same time where checking if dir exists is not atomic with the creation