Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 3243

Show
Ignore:
Timestamp:
01/29/08 19:24:00 (10 months ago)
Author:
tmdugan
Message:

-- dss

* added a method to rename a file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/dss/metadata/config.xml

    r3167 r3243  
    77        <id>dss</id> 
    88        <name>Dss</name> 
    9         <version>2.0</version> 
     9        <version>2.01</version> 
    1010        <package>org.openmrs.module.@MODULE_ID@</package> 
    1111        <author>Vibha Anand and Tammy Dugan</author> 
  • openmrs-modules/dss/src/org/openmrs/module/dss/util/IOUtil.java

    r3119 r3243  
    250250                } 
    251251        } 
     252         
     253        public static void renameFile(String oldname, String newname) 
     254        { 
     255                File file = new File(oldname); 
     256 
     257                if (!file.exists()) 
     258                { 
     259                        log.error("Rename failed. File does not exist."); 
     260                        return; 
     261                } 
     262 
     263                if (!file.canWrite()) 
     264                { 
     265                        log.error("Rename failed. File is not writable."); 
     266                        return; 
     267                } 
     268 
     269                // If it is a directory, make sure it is empty 
     270                if (file.isDirectory()) 
     271                { 
     272                        String[] files = file.list(); 
     273                        if (files.length > 0) 
     274                        { 
     275                                log.error("Rename failed. Directory is not empty."); 
     276                                return; 
     277                        } 
     278                } 
     279                 
     280                // Attempt to rename it 
     281                boolean success = file.renameTo(new File(newname)); 
     282 
     283                if (!success) 
     284                { 
     285                        //try garbage collection to release locks on file 
     286                        System.gc(); 
     287                        // Attempt to rename again 
     288                        success = file.renameTo(new File(newname)); 
     289                         
     290                        if(!success) 
     291                        { 
     292                                log.error("Rename failed. Could not rename file."); 
     293                        } 
     294                } 
     295        } 
    252296}