This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 247673
Collapse All | Expand All

(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/api/wizards/MakeSampleProjectGenerator.java (-4 / +16 lines)
Lines 54-59 Link Here
54
import java.io.InterruptedIOException;
54
import java.io.InterruptedIOException;
55
import java.io.OutputStream;
55
import java.io.OutputStream;
56
import java.io.OutputStreamWriter;
56
import java.io.OutputStreamWriter;
57
import java.net.ConnectException;
57
import java.net.URL;
58
import java.net.URL;
58
import java.util.ArrayList;
59
import java.util.ArrayList;
59
import java.util.Collection;
60
import java.util.Collection;
Lines 91-96 Link Here
91
import org.openide.filesystems.FileObject;
92
import org.openide.filesystems.FileObject;
92
import org.openide.filesystems.FileUtil;
93
import org.openide.filesystems.FileUtil;
93
import org.openide.filesystems.URLMapper;
94
import org.openide.filesystems.URLMapper;
95
import org.openide.util.Exceptions;
94
import org.openide.util.Lookup;
96
import org.openide.util.Lookup;
95
import org.openide.util.Utilities;
97
import org.openide.util.Utilities;
96
import org.openide.xml.XMLUtil;
98
import org.openide.xml.XMLUtil;
Lines 448-457 Link Here
448
            prjLoc = FileUtil.createFolder(prjParams.getSourceFileSystem().getRoot(), projectFolderPath);
450
            prjLoc = FileUtil.createFolder(prjParams.getSourceFileSystem().getRoot(), projectFolderPath);
449
        }
451
        }
450
        unzip(inputStream, prjLoc);
452
        unzip(inputStream, prjLoc);
451
        postProcessProject(prjLoc, prjParams.getProjectName(), prjParams);
453
        FileSystemProvider.suspendWritesUpload(prjLoc);
452
        customPostProcessProject(prjLoc, prjParams.getProjectName(), prjParams);
454
        try {
453
455
            postProcessProject(prjLoc, prjParams.getProjectName(), prjParams);
454
        prjLoc.refresh(false);
456
            customPostProcessProject(prjLoc, prjParams.getProjectName(), prjParams);
457
        } finally {
458
            try {
459
                FileSystemProvider.resumeWritesUpload(prjLoc);
460
            } catch (InterruptedException ex) {
461
                InterruptedIOException iioe = new InterruptedIOException(ex.getMessage());
462
                iioe.setStackTrace(ex.getStackTrace());
463
                throw iioe;
464
            }
465
            prjLoc.refresh(false);
466
        }
455
467
456
        return Collections.singleton(prjLoc);
468
        return Collections.singleton(prjLoc);
457
    }
469
    }
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java (-28 / +105 lines)
Lines 67-73 Link Here
67
import java.util.logging.Level;
67
import java.util.logging.Level;
68
import java.util.zip.ZipEntry;
68
import java.util.zip.ZipEntry;
69
import java.util.zip.ZipFile;
69
import java.util.zip.ZipFile;
70
import java.util.zip.ZipOutputStream;
70
import org.netbeans.api.annotations.common.NonNull;
71
import org.netbeans.api.annotations.common.NonNull;
72
import org.netbeans.modules.dlight.libs.common.DLightLibsCommonLogger;
71
import org.netbeans.modules.dlight.libs.common.PathUtilities;
73
import org.netbeans.modules.dlight.libs.common.PathUtilities;
72
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
74
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
73
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport;
75
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport;
Lines 246-251 Link Here
246
    }
248
    }
247
249
248
    private RemoteFileObject create(String name, boolean directory, RemoteFileObjectBase orig) throws IOException {
250
    private RemoteFileObject create(String name, boolean directory, RemoteFileObjectBase orig) throws IOException {
251
        if(isSuspendedWritesUpload()) {
252
            // TODO: shouldn't it be done even if not suspended?
253
            RemoteFileObject fo = getFileObject(name, new HashSet<String>());
254
            if (fo != null) {
255
                return fo;
256
            }
257
        }
249
        // Have to comment this out since NB does lots of stuff in the UI thread and I have no way to control this :(
258
        // Have to comment this out since NB does lots of stuff in the UI thread and I have no way to control this :(
250
        // RemoteLogger.assertNonUiThread("Remote file operations should not be done in UI thread");
259
        // RemoteLogger.assertNonUiThread("Remote file operations should not be done in UI thread");
251
        String path = getPath() + '/' + name;
260
        String path = getPath() + '/' + name;
Lines 1461-1469 Link Here
1461
        }
1470
        }
1462
    }
1471
    }
1463
1472
1464
    void uploadAndUnzip(InputStream zipStream) throws ConnectException, InterruptedException, IOException {
1473
    boolean isSuspendedWritesUpload() {
1474
        for(RemoteFileObjectBase fo = this; fo != null; fo = fo.getParent()) {
1475
            if (fo.getFlag(MASK_SUSPEND_WRITES)) {
1476
                return true;
1477
            }
1478
        }
1479
        return false;
1480
    }
1481
    
1482
    boolean addSuspendedFile(RemotePlainFile fo) {
1483
        for(RemoteFileObjectBase parent = this; parent != null; parent = parent.getParent()) {
1484
            if (parent.getFlag(MASK_SUSPEND_WRITES)) {
1485
                if (parent instanceof RemoteDirectory) {
1486
                    getFileSystem().addSuspendedFile((RemoteDirectory) parent, fo);
1487
                    return true;
1488
                }
1489
            }
1490
        }
1491
        return false;
1492
    }
1493
1494
    void suspendWritesUpload() {
1495
        setFlag(MASK_SUSPEND_WRITES, true);
1496
    }
1497
1498
    void resumeWritesUpload() throws IOException, InterruptedException, ConnectException {
1499
        setFlag(MASK_SUSPEND_WRITES, false);
1465
        final ExecutionEnvironment env = getExecutionEnvironment();
1500
        final ExecutionEnvironment env = getExecutionEnvironment();
1466
        if (!ConnectionManager.getInstance().isConnectedTo(env)) {
1501
        if (!ConnectionManager.getInstance().isConnectedTo(env)) {
1502
            throw RemoteExceptions.createConnectException(RemoteFileSystemUtils.getConnectExceptionMessage(env));
1503
        }        
1504
        Set<RemotePlainFile> files = getFileSystem().removeSuspendedFiles(this);
1505
        if (files == null || files.isEmpty()) {
1506
            return;
1507
        }
1508
        File zipFile = File.createTempFile("rfs_local", ".zip");
1509
        try {
1510
            try (ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(zipFile))) {
1511
                for (RemotePlainFile fo : files) {
1512
                    String path = fo.getPath();
1513
                    if (path.startsWith(getPath()) && path.length() > getPath().length()+1 && path.charAt(getPath().length()) == '/') {
1514
                        String relPath = path.substring(getPath().length() + 1);
1515
                        ZipEntry entry = new ZipEntry(relPath);
1516
                        //entry.setTime(file.lastModified());
1517
                        zipStream.putNextEntry(entry);
1518
                        try (FileInputStream fis = new FileInputStream(fo.getCache())) {
1519
                            FileUtil.copy(fis, zipStream);                            
1520
                        }
1521
                    } else {
1522
                        // TODO: log it!
1523
                    }
1524
                }
1525
            }
1526
            uploadAndUnzip(zipFile);
1527
            for (RemotePlainFile fo : files) {
1528
                fo.setPendingRemoteDelivery(false);
1529
            }
1530
        } finally {
1531
            zipFile.delete();
1532
        }
1533
    }
1534
1535
    void uploadAndUnzip(InputStream zipStream) throws ConnectException, InterruptedException, IOException {        
1536
        final ExecutionEnvironment env = getExecutionEnvironment();        
1537
        if (!ConnectionManager.getInstance().isConnectedTo(env)) {
1467
            zipStream.close();
1538
            zipStream.close();
1468
            throw RemoteExceptions.createConnectException(RemoteFileSystemUtils.getConnectExceptionMessage(env));
1539
            throw RemoteExceptions.createConnectException(RemoteFileSystemUtils.getConnectExceptionMessage(env));
1469
        }        
1540
        }        
Lines 1477-1509 Link Here
1477
            } finally {
1548
            } finally {
1478
                zipStream.close();
1549
                zipStream.close();
1479
            }
1550
            }
1480
            // Copy local zip file to remote
1551
            uploadAndUnzip(localZipFO);            
1481
            FileObject remoteZipFO = getFileSystem().createTempFile(this.getOwnerFileObject(), RemoteFileSystem.TEMP_ZIP_PREFIX, ".zip", false); //NOI18N
1482
            try (OutputStream os = remoteZipFO.getOutputStream()) {
1483
                try (InputStream is = new FileInputStream(localZipFO)) {
1484
                    FileUtil.copy(is, os);
1485
                }
1486
            }
1487
            StringBuilder script = new StringBuilder("unzip -q ").append(remoteZipFO.getPath()).append(" && rm ").append(remoteZipFO.getPath()); //NOI18N
1488
//            if (adjustLineEndings && Utils.isWindows()) {
1489
//                script.append(" && (which dos2unix > /dev/null; if [ $? = 0 ]; then find . -name \"*[Mm]akefile*\" -exec dos2unix {}  \\; ; else echo \"no_dos2unix\"; fi)"); //NOI18N
1490
//            }
1491
            ProcessUtils.ExitStatus rc = ProcessUtils.executeInDir(getPath(), env,
1492
                    "sh", /*"-x",*/ "-c", script.toString()); //NOI18N
1493
            if (!rc.isOK()) {
1494
                throw new IOException(rc.getErrorString() + " when unzipping and removing " + remoteZipFO.getPath() + " in " + this); //NOI18N
1495
            }
1496
            getCache().mkdirs();
1497
            try (InputStream is = new FileInputStream(localZipFO)) {
1498
                RemoteFileSystemUtils.unpackZipFile(is, getCache());
1499
            }
1500
            try {
1501
                refreshImpl(trace, null, true, RefreshMode.DEFAULT, 0);
1502
            } catch (TimeoutException ex) {
1503
                RemoteFileSystemUtils.reportUnexpectedTimeout(ex, this);
1504
            } catch (ExecutionException ex) {
1505
                throw new IOException(ex);
1506
            }            
1507
        } finally {
1552
        } finally {
1508
            if (localZipFO != null) {
1553
            if (localZipFO != null) {
1509
                localZipFO.delete();
1554
                localZipFO.delete();
Lines 1511-1516 Link Here
1511
        }        
1556
        }        
1512
    }
1557
    }
1513
1558
1559
    @SuppressWarnings("ReplaceStringBufferByString")
1560
    private void uploadAndUnzip(File localZipFO) throws InterruptedException, IOException {
1561
        final ExecutionEnvironment env = getExecutionEnvironment();
1562
        // Copy local zip file to remote
1563
        FileObject remoteZipFO = getFileSystem().createTempFile(this.getOwnerFileObject(), RemoteFileSystem.TEMP_ZIP_PREFIX, ".zip", false); //NOI18N
1564
        try (OutputStream os = remoteZipFO.getOutputStream()) {
1565
            try (InputStream is = new FileInputStream(localZipFO)) {
1566
                FileUtil.copy(is, os);
1567
            }
1568
        }
1569
        StringBuilder script = new StringBuilder("unzip -q -o ").append(remoteZipFO.getPath()).append(" && rm ").append(remoteZipFO.getPath()); //NOI18N
1570
//            if (adjustLineEndings && Utils.isWindows()) {
1571
//                script.append(" && (which dos2unix > /dev/null; if [ $? = 0 ]; then find . -name \"*[Mm]akefile*\" -exec dos2unix {}  \\; ; else echo \"no_dos2unix\"; fi)"); //NOI18N
1572
//            }
1573
        ProcessUtils.ExitStatus rc = ProcessUtils.executeInDir(getPath(), env,
1574
                "sh", "-c", script.toString()); //NOI18N
1575
        if (!rc.isOK()) {
1576
            throw new IOException(rc.getErrorString() + " when unzipping and removing " + remoteZipFO.getPath() + " in " + this); //NOI18N
1577
        }
1578
        getCache().mkdirs();
1579
        try (InputStream is = new FileInputStream(localZipFO)) {
1580
            RemoteFileSystemUtils.unpackZipFile(is, getCache());
1581
        }
1582
        try {
1583
            refreshImpl(trace, null, true, RefreshMode.DEFAULT, 0);
1584
        } catch (TimeoutException ex) {
1585
            RemoteFileSystemUtils.reportUnexpectedTimeout(ex, this);
1586
        } catch (ExecutionException ex) {
1587
            throw new IOException(ex);
1588
        }
1589
    }
1590
1514
    private boolean ensureChildSyncFromZip(RemotePlainFile child) {
1591
    private boolean ensureChildSyncFromZip(RemotePlainFile child) {
1515
        File file = new File(getCache(), RemoteFileSystem.CACHE_ZIP_FILE_NAME);
1592
        File file = new File(getCache(), RemoteFileSystem.CACHE_ZIP_FILE_NAME);
1516
        if (file.exists()) {
1593
        if (file.exists()) {
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileObjectBase.java (-1 / +2 lines)
Lines 103-108 Link Here
103
    protected static final byte CONNECTION_ISSUES = 8;
103
    protected static final byte CONNECTION_ISSUES = 8;
104
    protected static final byte MASK_WARMUP = 16;
104
    protected static final byte MASK_WARMUP = 16;
105
    protected static final byte MASK_CYCLIC_LINK = 32;
105
    protected static final byte MASK_CYCLIC_LINK = 32;
106
    protected static final byte MASK_SUSPEND_WRITES = 64;
106
107
107
    protected RemoteFileObjectBase(RemoteFileObject wrapper, RemoteFileSystem fileSystem, ExecutionEnvironment execEnv,
108
    protected RemoteFileObjectBase(RemoteFileObject wrapper, RemoteFileSystem fileSystem, ExecutionEnvironment execEnv,
108
            RemoteFileObjectBase parent, String remotePath) {
109
            RemoteFileObjectBase parent, String remotePath) {
Lines 980-984 Link Here
980
981
981
    protected RemoteLockSupport getLockSupport() {
982
    protected RemoteLockSupport getLockSupport() {
982
        return fileSystem.getLockSupport();
983
        return fileSystem.getLockSupport();
983
    }
984
    }    
984
}
985
}
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystem.java (+20 lines)
Lines 57-62 Link Here
57
import java.io.ObjectOutputStream;
57
import java.io.ObjectOutputStream;
58
import java.net.ConnectException;
58
import java.net.ConnectException;
59
import java.util.*;
59
import java.util.*;
60
import java.util.concurrent.ConcurrentHashMap;
60
import java.util.concurrent.CopyOnWriteArrayList;
61
import java.util.concurrent.CopyOnWriteArrayList;
61
import java.util.concurrent.ExecutionException;
62
import java.util.concurrent.ExecutionException;
62
import java.util.concurrent.atomic.AtomicBoolean;
63
import java.util.concurrent.atomic.AtomicBoolean;
Lines 149-154 Link Here
149
    private final ThreadLocal<Integer> isInsideVCS = new ThreadLocal<>();
150
    private final ThreadLocal<Integer> isInsideVCS = new ThreadLocal<>();
150
    private final ThreadLocal<Boolean> isGettingDirectoryStorage = new ThreadLocal<>();
151
    private final ThreadLocal<Boolean> isGettingDirectoryStorage = new ThreadLocal<>();
151
152
153
    private final Map<RemoteDirectory, Set<RemotePlainFile>> suspendedFiles = new HashMap<>();
154
152
    private final RequestProcessor.Task connectionTask;
155
    private final RequestProcessor.Task connectionTask;
153
156
154
    /** 
157
    /** 
Lines 1151-1156 Link Here
1151
            return fo.lastModified().getTime();
1154
            return fo.lastModified().getTime();
1152
        }
1155
        }
1153
    }
1156
    }
1157
    
1158
    /*package*/ void addSuspendedFile(RemoteDirectory dir, RemotePlainFile fo) {
1159
        synchronized(suspendedFiles) {
1160
            Set<RemotePlainFile> set = suspendedFiles.get(dir);
1161
            if (set == null) {
1162
                set = new HashSet();
1163
                suspendedFiles.put(dir, set);
1164
            }
1165
            set.add(fo);
1166
        }
1167
    }
1168
    
1169
    /*package*/ Set<RemotePlainFile> removeSuspendedFiles(RemoteDirectory dir) {
1170
        synchronized(suspendedFiles) {
1171
            return suspendedFiles.remove(dir);
1172
        }
1173
    }
1154
1174
1155
    private final class StatusImpl implements StatusDecorator, ImageDecorator, LookupListener, FileStatusListener {
1175
    private final class StatusImpl implements StatusDecorator, ImageDecorator, LookupListener, FileStatusListener {
1156
1176
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystemProvider.java (-1 / +42 lines)
Lines 544-550 Link Here
544
            } else {
544
            } else {
545
                throw new IOException("Unexpected file object class for " + impl + //NOI18N
545
                throw new IOException("Unexpected file object class for " + impl + //NOI18N
546
                        ", expected " + RemoteDirectory.class.getSimpleName() + //NOI18N
546
                        ", expected " + RemoteDirectory.class.getSimpleName() + //NOI18N
547
                        " initial FileObjec " + targetFolder); //NOI18N
547
                        " initial FileObject " + targetFolder); //NOI18N
548
            }
549
        }
550
    }
551
552
    @Override
553
    public void suspendWritesUpload(FileObject folder) throws IOException {
554
        if (folder instanceof RemoteFileObject) {
555
            RemoteFileObjectBase impl = ((RemoteFileObject) folder).getImplementor();            
556
            while (impl instanceof RemoteLinkBase) {
557
                RemoteFileObjectBase delegate = ((RemoteLinkBase) impl).getCanonicalDelegate();
558
                if (delegate != null) {
559
                    impl = delegate;
560
                }
561
            }
562
            if (impl instanceof RemoteDirectory) {
563
                ((RemoteDirectory) impl).suspendWritesUpload();
564
            } else {
565
                throw new IOException("Unexpected file object class for " + impl + //NOI18N
566
                        ", expected " + RemoteDirectory.class.getSimpleName() + //NOI18N
567
                        " initial FileObject " + folder); //NOI18N
568
            }
569
        }
570
    }
571
572
    @Override
573
    public void resumeWritesUpload(FileObject folder) 
574
        throws IOException, InterruptedException, ConnectException {
575
        if (folder instanceof RemoteFileObject) {
576
            RemoteFileObjectBase impl = ((RemoteFileObject) folder).getImplementor();            
577
            while (impl instanceof RemoteLinkBase) {
578
                RemoteFileObjectBase delegate = ((RemoteLinkBase) impl).getCanonicalDelegate();
579
                if (delegate != null) {
580
                    impl = delegate;
581
                }
582
            }
583
            if (impl instanceof RemoteDirectory) {
584
                ((RemoteDirectory) impl).resumeWritesUpload();
585
            } else {
586
                throw new IOException("Unexpected file object class for " + impl + //NOI18N
587
                        ", expected " + RemoteDirectory.class.getSimpleName() + //NOI18N
588
                        " initial FileObject " + folder); //NOI18N
548
            }
589
            }
549
        }
590
        }
550
    }
591
    }
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemotePlainFile.java (-1 / +3 lines)
Lines 499-505 Link Here
499
            try {
499
            try {
500
                delegate.close();
500
                delegate.close();
501
                RemotePlainFile.this.setPendingRemoteDelivery(true);
501
                RemotePlainFile.this.setPendingRemoteDelivery(true);
502
502
                if (getParentImpl().addSuspendedFile(RemotePlainFile.this)) {
503
                    return;
504
                }
503
                String pathToRename, pathToUpload;
505
                String pathToRename, pathToUpload;
504
506
505
                if (RemotePlainFile.this.getParent().canWrite()) {
507
                if (RemotePlainFile.this.getParent().canWrite()) {
(-)a/dlight.remote/src/org/netbeans/modules/remote/spi/FileSystemProvider.java (+30 lines)
Lines 674-679 Link Here
674
        noProvidersWarning(targetFolder);
674
        noProvidersWarning(targetFolder);
675
    }
675
    }
676
676
677
    /**
678
     * NB #1: does NOT support links inside directory!
679
     * NB #2: does NOT support transform file names, they will be exactly the same
680
     */
681
    public static void suspendWritesUpload(FileObject folder) throws IOException {
682
        DLightLibsCommonLogger.assertTrue(folder.isFolder(), "Not a folder: " + folder); //NOI18N
683
        for (FileSystemProviderImplementation provider : ALL_PROVIDERS) {
684
            if (provider.isMine(folder)) {
685
                provider.suspendWritesUpload(folder);
686
                return;
687
            }
688
        }
689
        noProvidersWarning(folder);
690
    }
691
692
    /**
693
     * NB: does NOT support links inside directory!
694
     */
695
    public static void resumeWritesUpload(FileObject folder) 
696
            throws IOException, InterruptedException, ConnectException {
697
        DLightLibsCommonLogger.assertTrue(folder.isFolder(), "Not a folder: " + folder); //NOI18N
698
        for (FileSystemProviderImplementation provider : ALL_PROVIDERS) {
699
            if (provider.isMine(folder)) {
700
                provider.resumeWritesUpload(folder);
701
                return;
702
            }
703
        }
704
        noProvidersWarning(folder);
705
    }
706
677
    private static void noProvidersWarning(Object object) {
707
    private static void noProvidersWarning(Object object) {
678
        if (RemoteLogger.getInstance().isLoggable(Level.FINE)) {        
708
        if (RemoteLogger.getInstance().isLoggable(Level.FINE)) {        
679
            if (RemoteLogger.getInstance().isLoggable(Level.FINEST)) {
709
            if (RemoteLogger.getInstance().isLoggable(Level.FINEST)) {
(-)a/dlight.remote/src/org/netbeans/modules/remote/spi/FileSystemProviderImplementation.java (+2 lines)
Lines 114-117 Link Here
114
    FileSystemProvider.Stat getStat(FileObject fo);
114
    FileSystemProvider.Stat getStat(FileObject fo);
115
    void uploadAndUnzip(InputStream zipStream, FileObject targetFolder) 
115
    void uploadAndUnzip(InputStream zipStream, FileObject targetFolder) 
116
            throws FileNotFoundException, ConnectException, IOException, InterruptedException;
116
            throws FileNotFoundException, ConnectException, IOException, InterruptedException;
117
    void suspendWritesUpload(FileObject folder) throws IOException;
118
    void resumeWritesUpload(FileObject folder) throws IOException, InterruptedException, ConnectException;
117
}
119
}
(-)a/dlight.remote/src/org/netbeans/modules/remote/support/LocalFileSystemProvider.java (+8 lines)
Lines 565-568 Link Here
565
            }
565
            }
566
        }
566
        }
567
    }
567
    }
568
569
    @Override
570
    public void suspendWritesUpload(FileObject folder) {
571
    }
572
573
    @Override
574
    public void resumeWritesUpload(FileObject folder) {
575
    }
568
}
576
}

Return to bug 247673