imaffe commented on issue #2067:
URL: https://github.com/apache/rocketmq/issues/2067#issuecomment-645163000


   ```
       public static double getDiskPartitionSpaceUsedPercent(final String path) 
{
           if (null == path || path.isEmpty())
               return -1;
   
           try {
               File file = new File(path);
   
               if (!file.exists())
                   return -1;
   
               long totalSpace = file.getTotalSpace();
   
               if (totalSpace > 0) {
                   long freeSpace = file.getFreeSpace();
                   long usedSpace = totalSpace - freeSpace;
   
                   return usedSpace / (double) totalSpace;
               }
           } catch (Exception e) {
               return -1;
           }
   
           return -1;
       }
   ```
   
   Here, if filePath is null or empty or got an exception, the ratio would be 
-1; I would recommend use [Arthas](https://alibaba.github.io/arthas/) to make 
sure the filePath is valid. Then we can try to print out the Exception message 
here and see if it is permission related problems.
   
   And I think this place we need to log what the exception is or record what 
is the cause of returning -1. If you are interested in enhance this place feel 
free to submit a PR.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to