Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d98ff4f
extensions: add sync functionality
shwstppr Oct 7, 2025
d7d9a4a
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Oct 10, 2025
4a535bd
more tests
shwstppr Oct 10, 2025
0337e34
missing file
shwstppr Oct 10, 2025
c91a970
fix line endings
shwstppr Oct 10, 2025
d384fb2
Merge branch 'main' into feature-sync-ext
shwstppr Oct 10, 2025
ecbdcd6
do not use mockConstruction
shwstppr Oct 10, 2025
2c70e03
changes
shwstppr Oct 11, 2025
2be9d96
changes for download extension
shwstppr Oct 12, 2025
40b013d
fix lint and rat check
shwstppr Oct 13, 2025
2da3004
add more tests
shwstppr Oct 13, 2025
fdfcfe6
fix lint
shwstppr Oct 13, 2025
942f36e
handle when share context is disabled
shwstppr Oct 14, 2025
f923de8
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Oct 26, 2025
5525242
changes for download via ssvm/secondary store
shwstppr Oct 29, 2025
865c6fd
allow cleanup of archives on sec store
shwstppr Oct 30, 2025
6276cd6
allow share context for lacal maven run, refactor
shwstppr Nov 2, 2025
c6b677b
refactor
shwstppr Nov 2, 2025
480fa9d
add tests
shwstppr Nov 3, 2025
0f5f3da
more tests and refactor
shwstppr Nov 3, 2025
2332c9c
log fix
shwstppr Nov 3, 2025
5b09704
Merge branch 'main' into feature-sync-ext
DaanHoogland Dec 22, 2025
de78f5b
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Dec 29, 2025
02c87ea
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Jan 28, 2026
5220a3e
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Jan 29, 2026
35903ed
fix build
shwstppr Jan 29, 2026
1998867
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Jan 31, 2026
07e70f2
secondary-storage: delete temp directory while deleting entity download
shwstppr Jan 31, 2026
21419d1
fix
shwstppr Jan 31, 2026
6941097
refactor
shwstppr Feb 6, 2026
6519e55
address copilot comments
shwstppr Feb 6, 2026
e895355
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Apr 11, 2026
49d9b76
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Apr 14, 2026
23360ac
address comment
shwstppr Apr 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
secondary-storage: delete temp directory while deleting entity download
url

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
  • Loading branch information
shwstppr committed Jan 31, 2026
commit 07e70f2f4c1b2feff425894bdd8e2727eda22ff0
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.naming.ConfigurationException;

import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
import org.apache.commons.lang3.StringUtils;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.ConvertSnapshotCommand;
Expand All @@ -52,7 +53,9 @@
import com.cloud.storage.template.TemplateUploader;
import com.cloud.storage.template.TemplateUploader.Status;
import com.cloud.storage.template.TemplateUploader.UploadCompleteCallback;
import com.cloud.utils.FileUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.UuidUtils;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
Expand Down Expand Up @@ -347,6 +350,7 @@ public Answer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLComman
// This is because the ssvm might already be destroyed and the symlinks do not exist.
logger.warn("Error in deleting symlink :" + result);
}
deleteEntitySymlinkRootPathIfNeeded(cmd, linkPath);
}

// If its a volume or archive also delete the Hard link since it was created only for the purpose of download.
Expand Down Expand Up @@ -380,6 +384,30 @@ public Answer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLComman
return new Answer(cmd, true, "");
}

protected void deleteEntitySymlinkRootPathIfNeeded(DeleteEntityDownloadURLCommand cmd, String linkPath) {
if (StringUtils.isEmpty(linkPath)) {
return;
}
String[] parts = linkPath.split("/");
if (parts.length == 0) {
return;
}
String rootDir = parts[0];
if (StringUtils.isEmpty(rootDir) || !UuidUtils.isUuid(rootDir)) {
return;
}
logger.info("Deleting symlink root directory: {} for {}", rootDir, cmd.getExtractUrl());
Path rootDirPath = Path.of(BASE_EXTRACT_DIR + rootDir);
String failMsg = "Failed to delete symlink root directory: {} for {}";
try {
if (!FileUtil.deleteRecursively(rootDirPath)) {
logger.warn(failMsg, rootDir, cmd.getExtractUrl());
}
} catch (IOException e) {
logger.warn(failMsg, rootDir, cmd.getExtractUrl(), e);
}
}

private String getInstallPath(String jobId) {
// TODO Auto-generated method stub
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.storage.template;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;

import java.nio.file.Path;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
import com.cloud.utils.FileUtil;

@RunWith(MockitoJUnitRunner.class)
public class UploadManagerImplTest {

@InjectMocks
UploadManagerImpl uploadManager;

MockedStatic<FileUtil> fileUtilMock;

@Before
public void setup() {
fileUtilMock = mockStatic(FileUtil.class, Mockito.CALLS_REAL_METHODS);
fileUtilMock.when(() -> FileUtil.deleteRecursively(any(Path.class))).thenReturn(true);
}

@After
public void tearDown() {
fileUtilMock.close();
}

@Test
public void doesNotDeleteWhenLinkPathIsEmpty() {
String emptyLinkPath = "";
uploadManager.deleteEntitySymlinkRootPathIfNeeded(mock(DeleteEntityDownloadURLCommand.class), emptyLinkPath);
fileUtilMock.verify(() -> FileUtil.deleteRecursively(any(Path.class)), never());
}

@Test
public void doesNotDeleteWhenRootDirIsNotUuid() {
String invalidLinkPath = "invalidRootDir/file";
uploadManager.deleteEntitySymlinkRootPathIfNeeded(mock(DeleteEntityDownloadURLCommand.class), invalidLinkPath);
fileUtilMock.verify(() -> FileUtil.deleteRecursively(any(Path.class)), never());
}

@Test
public void deletesSymlinkRootDirectoryWhenValidUuid() {
String validLinkPath = "123e4567-e89b-12d3-a456-426614174000/file";
uploadManager.deleteEntitySymlinkRootPathIfNeeded(mock(DeleteEntityDownloadURLCommand.class), validLinkPath);
fileUtilMock.verify(() -> FileUtil.deleteRecursively(any(Path.class)), times(1));
}
}
Loading