6060
6161public class UploadManagerImpl extends ManagerBase implements UploadManager {
6262
63- protected static final String BASE_EXTRACT_DIR = "/var/www/html/userdata/" ;
63+ protected static final String EXTRACT_USERDATA_DIR = "userdata" ;
64+ protected static final String BASE_EXTRACT_PATH = String .format ("/var/www/html/%s/" , EXTRACT_USERDATA_DIR );
6465
6566 public class Completion implements UploadCompleteCallback {
6667 private final String jobId ;
@@ -271,7 +272,7 @@ public CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDo
271272 return new CreateEntityDownloadURLAnswer (errorString , CreateEntityDownloadURLAnswer .RESULT_FAILURE );
272273 }
273274 // Create the directory structure so that its visible under apache server root
274- String extractDir = BASE_EXTRACT_DIR ;
275+ String extractDir = BASE_EXTRACT_PATH ;
275276 extractDir = extractDir + cmd .getFilepathInExtractURL () + File .separator ;
276277 Script command = new Script ("/bin/su" , logger );
277278 command .add ("-s" );
@@ -335,15 +336,20 @@ public Answer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLComman
335336 String extractUrl = cmd .getExtractUrl ();
336337 String result ;
337338 if (extractUrl != null ) {
338- String linkPath = extractUrl .substring (extractUrl .lastIndexOf (File .separator ) + 1 );
339- command .add ("unlink " + BASE_EXTRACT_DIR + linkPath );
339+ URI uri = URI .create (extractUrl );
340+ String uriPath = uri .getPath ();
341+ String marker = String .format ("/%s/" , EXTRACT_USERDATA_DIR );
342+ String linkPath = uriPath .startsWith (marker )
343+ ? uriPath .substring (marker .length ())
344+ : uriPath .substring (uriPath .indexOf (marker ) + marker .length ());
345+ command .add ("unlink " + BASE_EXTRACT_PATH + linkPath );
340346 result = command .execute ();
341347 if (result != null ) {
342348 // FIXME - Ideally should bail out if you can't delete symlink. Not doing it right now.
343349 // This is because the ssvm might already be destroyed and the symlinks do not exist.
344350 logger .warn ("Error in deleting symlink :" + result );
345351 } else {
346- deleteEntitySymlinkRootPathIfNeeded (cmd , linkPath );
352+ deleteEntitySymlinkRootDirectoryIfNeeded (cmd , linkPath );
347353 }
348354 }
349355
@@ -364,7 +370,7 @@ public Answer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLComman
364370 return new Answer (cmd , true , "" );
365371 }
366372
367- protected void deleteEntitySymlinkRootPathIfNeeded (DeleteEntityDownloadURLCommand cmd , String linkPath ) {
373+ protected void deleteEntitySymlinkRootDirectoryIfNeeded (DeleteEntityDownloadURLCommand cmd , String linkPath ) {
368374 if (StringUtils .isEmpty (linkPath )) {
369375 return ;
370376 }
@@ -377,7 +383,7 @@ protected void deleteEntitySymlinkRootPathIfNeeded(DeleteEntityDownloadURLComman
377383 return ;
378384 }
379385 logger .info ("Deleting symlink root directory: {} for {}" , rootDir , cmd .getExtractUrl ());
380- Path rootDirPath = Path .of (BASE_EXTRACT_DIR + rootDir );
386+ Path rootDirPath = Path .of (BASE_EXTRACT_PATH + rootDir );
381387 String failMsg = "Failed to delete symlink root directory: {} for {}" ;
382388 try {
383389 if (!FileUtil .deleteRecursively (rootDirPath )) {
0 commit comments