File access

Post

Posted
Rating:
#1 (In Topic #1426)
Avatar
Regular
mandarin is in the usergroup ‘Regular’
In order to make Gambas3 access a file, should I "chmod 600 filename" (-rw——-) every time I write a program, or is the default "chmod 644 filename" (-rw-r–r–) ok?

Is there another chmod used as default for Gambas3 programs?

Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 The default should be OK.

But, how are you trying to access the file? Beware of relative paths and what they mean.

b

Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
mandarin is in the usergroup ‘Regular’
For ease of compiling, I always place the necessary files in a subdirectory (say "/archives") of my project; and usually insert this part of code, after defining the file path:

Code (gambas)

  1. Public Sub File1_initialize()
  2.  
  3.   Dim hFile As File
  4.   Dim var1Shellvar As String
  5.  
  6.   If Not Exist(sFilePath1) Then
  7.     hFile = Open sFilePath1 For Create
  8.     Close #hFile
  9.   Else
  10.     Shell "stat --format '%a' " & Quote(sFilePath1) To var1Shellvar
  11.   'giving access to the file
  12.     If Val(var1Shellvar) <> 600 Then
  13.       Shell "chmod 0600 " & Quote(sFilePath1) Wait
  14.     Endif
  15.   Endif
  16.  

During my initial trials of Gambas3, for some reasons mode 644 did not provide access. Instead, mode 600 worked very well.

Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
gambas has commands
Access() /lang/access - Gambas Documentation
and Chmod.. /lang/chmod - Gambas Documentation
and Stat() /lang/stat - Gambas Documentation

Code (gambas)

  1.  
  2. If Not Access(sFilePath, gb.Write) Then ChMod sFilePath To "rw-rw-rw-"
  3.  
  4.  

Or

Code (gambas)

  1. Dim hStat As Stat = Stat(sFilePath)
  2. If InStr(hStat.Perm.Other, "r") Or If InStr(hStat.Perm.Group, "r") Then ChMod sFilePath To "rw-------"
  3.  

changing a file permission from -rw-r–r– to -rw——- should really not ,make a difference and may give you access problems elsewhere.

the order is Owner/Group/Others so you are removing the read flag from the Group and Other users just leaving Owner.  I can't see how that fixes your read issue.

I'd say you found an oddity as it is definitely NOT the case you have to change mode of every file you want to access.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
mandarin is in the usergroup ‘Regular’
I'd say you found an oddity

Maybe that's the case. Because at home I program on a standalone computer, but at school I program / experiment on a working LTSP server. (Both with Linux Mint, versions 22.1 and 21.3 respectively.)

Online now: No Back to the top
1 guest and 0 members have just viewed this.