Example 5. Finding And Creating A Thumbnail.
A program needs a thumbnail for ~/photos/me.jpeg with 64x64 in size.
Check if the file ~/photos/.thumbnails/64x64/me.jpeg.png exists. If it does go to number 7.
Check if the file ~/.thumbnails/64x64/home/'username'/photos/me.jpeg.png exists. If it does go to number 7.
Check if the file ~/photos/.thumbnails/fail/'programname'/me.jpeg.png exists. If it does go to number 7.
Check if the file ~/.thumbnails/fail/'programname'/me.jpeg.png exists. If it does go to number 7.
There hasn't been any thumbnail generated before. Go to number 9.
The program found a thumbnail. The next step is to check whether the image hase been modified. Use the algorithm described above. If there are no modifications go to number 16.
Delete the previous found thumbnail.
A thumbnail doesn't exist yet or the original has been modified since the last generation. Then the program must generate a new one.
If the generation of the thumb fails go to number 13.
If the user has write permissions in ~/photos save the the new thumbnail as ~/photos/.thumbnails/64x64/me.jpeg.png and goto number 16.
If the user has no write permission save the the new thumbnail as ~/.thumbnails/64x64/home/'username'/photos/me.jpeg.png and goto number 16.
If the user has write permission in ~/photos save the the failed thumbnail as ~/photos/.thumbnails/fail/'programname'/me.jpeg.png and goto number 15.
If the user has no write permission in ~/photos save the failed thumbnail as ~/.thumbnails/fail/'programname'/home/'username'/photos/me.jpeg.png.
The program is ready, but couldn't load the thumbnail.
The program is ready and can use the thumbnail.