1616package org .pgcodekeeper .core .database .base .project ;
1717
1818import org .pgcodekeeper .core .database .api .project .IProjectUpdater ;
19+ import org .pgcodekeeper .core .database .api .project .IWorkDirs ;
1920import org .pgcodekeeper .core .database .api .schema .IDatabase ;
2021import org .pgcodekeeper .core .exception .PgCodeKeeperException ;
2122import org .pgcodekeeper .core .localizations .Messages ;
3233import java .nio .file .attribute .BasicFileAttributes ;
3334import java .util .ArrayList ;
3435import java .util .Collection ;
36+ import java .util .LinkedHashSet ;
3537import java .util .List ;
38+ import java .util .Set ;
3639import java .util .stream .Stream ;
3740
3841import static org .pgcodekeeper .core .database .base .loader .AbstractProjectLoader .OVERRIDES_DIR ;
@@ -199,15 +202,16 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
199202 }
200203
201204 @ Override
202- public void updateFull (boolean projectOnly ) throws IOException {
205+ public void updateFull (boolean projectOnly , IWorkDirs previousWorkDirs ) throws IOException {
203206 LOG .info (Messages .ProjectUpdater_log_start_full_update );
204207 boolean caughtProcessingEx = false ;
205208 try (TempDir tmp = new TempDir (dirExport , "tmp-export" )) { //$NON-NLS-1$
206209 Path dirTmp = tmp .get ();
207210
208211 try {
209- safeCleanProjectDir (dirTmp );
210- createModelExporter (dirExport , dbNew , encoding ).exportFull ();
212+ AbstractModelExporter exporter = createModelExporter (dirExport , dbNew , encoding );
213+ safeCleanProjectDir (dirTmp , exporter .getWorkDirs (), previousWorkDirs );
214+ exporter .exportFull ();
211215 if (projectOnly ) {
212216 restoreFolder (dirTmp , OVERRIDES_DIR );
213217 }
@@ -227,8 +231,13 @@ public void updateFull(boolean projectOnly) throws IOException {
227231 }
228232 }
229233
230- private void safeCleanProjectDir (Path dirTmp ) throws IOException {
231- for (String subdirName : listProjectDirs (dirExport , dirTmp )) {
234+ private void safeCleanProjectDir (Path dirTmp , IWorkDirs workDirs , IWorkDirs previousWorkDirs ) throws IOException {
235+ Set <String > ownedDirs = new LinkedHashSet <>(workDirs .getTopLevelDirNames ());
236+ if (previousWorkDirs != null ) {
237+ ownedDirs .addAll (previousWorkDirs .getTopLevelDirNames ());
238+ }
239+ ownedDirs .add (OVERRIDES_DIR );
240+ for (String subdirName : ownedDirs ) {
232241 moveFolder (dirTmp , subdirName );
233242 }
234243 }
@@ -246,12 +255,15 @@ private void restoreProjectDir(Path dirTmp) throws IOException {
246255 }
247256 }
248257
249- private static List <String > listProjectDirs (Path dir , Path exclude ) throws IOException {
258+ private List <String > listProjectDirs (Path dir , Path exclude ) throws IOException {
250259 try (Stream <Path > stream = Files .list (dir )) {
251260 List <String > result = new ArrayList <>();
252261 for (Path path : Utils .streamIterator (stream )) {
253- if (Files .isDirectory (path ) && !path .equals (exclude )) {
254- result .add (path .getFileName ().toString ());
262+ String name = path .getFileName ().toString ();
263+ if (Files .isDirectory (path )
264+ && !path .equals (exclude )
265+ && !name .startsWith ("." )) {
266+ result .add (name );
255267 }
256268 }
257269 return result ;
0 commit comments