[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[tm-cvs-commit] dmcknight org.eclipse.tm.rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model ByteStreamHandler.java

Update of /cvsroot/tools/org.eclipse.tm.rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model
In directory dev1:/tmp/cvs-serv23066/src/org/eclipse/dstore/core/model

Modified Files:
      Tag: R3_2_maintenance
	ByteStreamHandler.java 
Log Message:
[380023] [dstore] remote file permissions lost after upload


Index: ByteStreamHandler.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.tm.rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/ByteStreamHandler.java,v
retrieving revision 1.8.2.4
retrieving revision 1.8.2.5
diff -C2 -d -r1.8.2.4 -r1.8.2.5
*** ByteStreamHandler.java	20 Mar 2012 20:15:10 -0000	1.8.2.4
--- ByteStreamHandler.java	22 May 2012 11:49:57 -0000	1.8.2.5
***************
*** 16,19 ****
--- 16,20 ----
   *  David McKnight     (IBM)   [281712] [dstore] Warning message is needed when disk is full
   *  David McKnight     (IBM)   [367424] [dstore] upload mechanism should provide backups of files
+  *  David McKnight     (IBM)   [380023] [dstore] remote file permissions lost after upload
   *******************************************************************************/
  
***************
*** 21,24 ****
--- 22,27 ----
  
  import java.io.File;
+ import java.io.FileInputStream;
+ import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
***************
*** 59,62 ****
--- 62,111 ----
  	}
  	
+ 	private void backupFile(File file, File backupFile){
+ 		
+ 		/* this is nice but orginal file permissions not perserved
+ 		if(!file.renameTo(backupFile) && backupFile.exists()) {
+ 			backupFile.delete();	
+ 			file.renameTo(backupFile);
+ 		}
+ 		*/
+ 		
+ 		/* in order to preserve original permissions for orignal file we can't rename
+ 		 * instead we need to copy the file over		 
+ 		 */
+ 		FileInputStream inputStream = null;
+ 		FileOutputStream backupFileStream = null;
+ 		try {
+ 			inputStream = new FileInputStream(file);
+ 			backupFileStream = new FileOutputStream(backupFile);
+ 			
+ 			byte[] buffer = new byte[512000];
+ 			long totalSize = file.length();
+ 			int totalRead = 0;
+ 
+ 			while (totalRead < totalSize){
+ 				int available = inputStream.available();
+ 				available = (available < 512000) ? available : 512000;
+ 
+ 				int bytesRead = inputStream.read(buffer, 0, available);
+ 				if (bytesRead == -1) {
+ 					break;
+ 				}
+ 				backupFileStream.write(buffer, 0, bytesRead);				
+ 				totalRead += bytesRead;
+ 			}			
+ 		} catch (FileNotFoundException e) {
+ 		} catch (IOException e){			
+ 		} finally {
+ 			try {
+ 				inputStream.close();
+ 				backupFileStream.close();
+ 			}
+ 			catch (IOException e){				
+ 			}
+ 		}
+ 	}
+ 	
+ 	
  	/**
  	 * Save a file in the specified location.  This method is called by the
***************
*** 88,105 ****
  				else
  				{
! 					// backup file on upload by default
! 					String doBackups = System.getProperty("backupfiles"); //$NON-NLS-1$
! 					if (doBackups == null || doBackups.equals("true")){ //$NON-NLS-1$
! 						// backup the file first	
! 						String n = file.getName();			
! 						File backupFile = new File(parent, '.' + n + '~');
! 						_dataStore.trace("Backing up as "+backupFile.getAbsolutePath()); //$NON-NLS-1$
! 						if(!file.renameTo(backupFile) && backupFile.exists()) {
! 							backupFile.delete();
! 							file.renameTo(backupFile);
  						}
  					}
  				}
! 				
  				File newFile = new File(fileName);				
  				FileOutputStream fileStream = new FileOutputStream(newFile);
--- 137,153 ----
  				else
  				{
! 					if (!_dataStore.isVirtual()){ // only applies to server
! 						// backup file on upload by default
! 						String doBackups = System.getProperty("backupfiles"); //$NON-NLS-1$
! 						if (doBackups == null || doBackups.equals("true")){ //$NON-NLS-1$
! 							// backup the file first	
! 							String n = file.getName();			
! 							File backupFile = new File(parent, '.' + n + '~');
! 							_dataStore.trace("Backing up as "+backupFile.getAbsolutePath()); //$NON-NLS-1$
! 							backupFile(file, backupFile);
  						}
  					}
  				}
! 
  				File newFile = new File(fileName);				
  				FileOutputStream fileStream = new FileOutputStream(newFile);