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()) { |